From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../testsuite/23_containers/vector/modifiers/1.cc | 55 +++++++ .../testsuite/23_containers/vector/modifiers/2.cc | 61 ++++++++ .../23_containers/vector/modifiers/erase/1.cc | 135 +++++++++++++++++ .../23_containers/vector/modifiers/erase/50529.cc | 38 +++++ .../vector/modifiers/erase/moveable.cc | 62 ++++++++ .../23_containers/vector/modifiers/insert/1.cc | 49 +++++++ .../23_containers/vector/modifiers/moveable.cc | 137 ++++++++++++++++++ .../23_containers/vector/modifiers/swap/1.cc | 62 ++++++++ .../23_containers/vector/modifiers/swap/2.cc | 132 +++++++++++++++++ .../23_containers/vector/modifiers/swap/3.cc | 161 +++++++++++++++++++++ 10 files changed, 892 insertions(+) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/1.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/2.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/50529.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/1.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc (limited to 'libstdc++-v3/testsuite/23_containers/vector/modifiers') diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/1.cc new file mode 100644 index 000000000..af0bedcee --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/1.cc @@ -0,0 +1,55 @@ +// 1999-11-09 bkoz + +// Copyright (C) 1999, 2001, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.2.4.3 vector modifiers + +#include +#include "testsuite_hooks.h" + +bool test __attribute__((unused)) = true; + +template + struct A { }; + +struct B { }; + +// vector::insert(iterator, inputiterator first, inputiterator last) +void +test01() +{ + // POD types + typedef std::vector vec_POD; + vec_POD vec01; + int i01 = 5; + int* pi01 = &i01; + vec01.insert(vec01.begin(), pi01, pi01 + 1); + + // non POD types + typedef std::vector< A > vec_nonPOD; + vec_nonPOD vec02; + A np01; + A* pnp01 = &np01; + vec02.insert(vec02.begin(), pnp01, pnp01 + 1); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/2.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/2.cc new file mode 100644 index 000000000..7e152891b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/2.cc @@ -0,0 +1,61 @@ +// 1999-11-09 bkoz + +// Copyright (C) 1999, 2001, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.2.4.3 vector modifiers + +#include +#include "testsuite_hooks.h" + +bool test __attribute__((unused)) = true; + +// test the assign() function +void +test03() +{ + const int K = 417; + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const int B[] = {K, K, K, K, K}; + const std::size_t N = sizeof(A) / sizeof(int); + const std::size_t M = sizeof(B) / sizeof(int); + bool test __attribute__((unused)) = true; + + // assign from pointer range + std::vector v3; + v3.assign(A, A + N); + VERIFY(std::equal(v3.begin(), v3.end(), A)); + VERIFY(v3.size() == N); + + // assign from iterator range + std::vector v4; + v4.assign(v3.begin(), v3.end()); + VERIFY(std::equal(v4.begin(), v4.end(), A)); + VERIFY(std::equal(A, A + N, v4.begin())); + + // assign from initializer range with resize + v4.assign(M, K); + VERIFY(std::equal(v4.begin(), v4.end(), B)); + VERIFY(std::equal(B, B + M, v4.begin())); + VERIFY((v4.size() == M) && (M != N)); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc new file mode 100644 index 000000000..2f695e432 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc @@ -0,0 +1,135 @@ +// 2005-11-02 Paolo Carlini + +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.2.4.3 vector modifiers + +#include +#include + +const int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15}; +const int A3[] = {0, 2, 3, 4, 10, 11}; +const int A4[] = {4, 10, 11}; +const int A5[] = {4, 10}; +const unsigned int N = sizeof(A) / sizeof(int); +const unsigned int N1 = sizeof(A1) / sizeof(int); +const unsigned int N2 = sizeof(A2) / sizeof(int); +const unsigned int N3 = sizeof(A3) / sizeof(int); +const unsigned int N4 = sizeof(A4) / sizeof(int); +const unsigned int N5 = sizeof(A5) / sizeof(int); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector vec_type; + typedef vec_type::iterator iterator_type; + + vec_type v(A, A + N); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector > vec_type; + typedef vec_type::iterator iterator_type; + + vec_type v, v1, v2, v3, v4, v5; + for (unsigned int i = 0; i < N; ++i) + v.push_back(std::vector(1, A[i])); + for (unsigned int i = 0; i < N1; ++i) + v1.push_back(std::vector(1, A1[i])); + for (unsigned int i = 0; i < N2; ++i) + v2.push_back(std::vector(1, A2[i])); + for (unsigned int i = 0; i < N3; ++i) + v3.push_back(std::vector(1, A3[i])); + for (unsigned int i = 0; i < N4; ++i) + v4.push_back(std::vector(1, A4[i])); + for (unsigned int i = 0; i < N5; ++i) + v5.push_back(std::vector(1, A5[i])); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), v1.begin()) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), v2.begin()) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), v3.begin()) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), v4.begin()) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), v5.begin()) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/50529.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/50529.cc new file mode 100644 index 000000000..d76bed53c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/50529.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-09-26 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +// libstdc++/50529 +void test01() +{ + std::vector<__gnu_test::rvalstruct> v(10); + + for (auto it = v.begin(); it != v.end(); ++it) + v.erase(it, it); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc new file mode 100644 index 000000000..9e0c5597e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-28 Paolo Carlini + +// Copyright (C) 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::vector a(40); + copycounter::copycount = 0; + + a.erase(a.begin() + 20); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 1); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin() + 10, a.end() - 10); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.begin() + 5); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 5, a.end()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.end()); + VERIFY( copycounter::copycount == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/1.cc new file mode 100644 index 000000000..dfd092dc5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/1.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + vector iv; + + try + { + iv.insert(iv.end(), iv.max_size() + 1, 1); + } + catch(std::length_error&) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc new file mode 100644 index 000000000..969cb1c92 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc @@ -0,0 +1,137 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +#include +#include +#include + +using namespace __gnu_test; + +// Test vector::push_back makes no unneeded copies. +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector a; + copycounter c(1); + copycounter::copycount = 0; + for(int i = 0; i < 10; ++i) + a.push_back(c); + VERIFY(copycounter::copycount == 10); + + for(int i = 0; i < 100; ++i) + a.insert(a.begin() + i, c); + VERIFY(copycounter::copycount == 110); + + for(int i = 0; i < 1000; ++i) + a.insert(a.end(), c); + VERIFY(copycounter::copycount == 1110); +} + +// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies +// when it has to also reallocate the vector's internal buffer. +void +test02() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector a(10, c), b(100, c); + copycounter::copycount = 0; + a.insert(a.begin(), b.begin(), b.begin() + 20); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), b.begin(), b.begin() + 50); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, b.begin(), b.end()); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies +// when it doesn't have to reallocate the vector's internal buffer. +void +test03() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector a(10, c), b(100, c); + copycounter::copycount = 0; + a.reserve(1000); + VERIFY(copycounter::copycount == 0); + a.insert(a.begin(), b.begin(), b.begin() + 20); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), b.begin(), b.begin() + 50); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, b.begin(), b.end()); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, count, value) makes no unneeded copies +// when it has to also reallocate the vector's internal buffer. +void +test04() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector a(10, c); + copycounter::copycount = 0; + a.insert(a.begin(), 20, c); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), 50, c); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, 100, c); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, count, value) makes no unneeded copies +// when it doesn't have to reallocate the vector's internal buffer. +void +test05() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector a(10, c); + copycounter::copycount = 0; + a.reserve(1000); + a.insert(a.begin(), 20, c); + // NOTE : These values are each one higher than might be expected, as + // vector::insert(iterator, count, value) copies the value it is given + // when it doesn't reallocate the buffer. + VERIFY(copycounter::copycount == 20 + 1); + a.insert(a.end(), 50, c); + VERIFY(copycounter::copycount == 70 + 2); + a.insert(a.begin() + 50, 100, c); + VERIFY(copycounter::copycount == 170 + 3); +} + + + +int main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc new file mode 100644 index 000000000..f4fd4d8d6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc @@ -0,0 +1,62 @@ +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct T { int i; }; + +int swap_calls; + +namespace std +{ + template<> + void + vector >::swap(vector >&) + { ++swap_calls; } +} + +// Should use vector specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::vector A; + std::vector B; + swap_calls = 0; + std::swap(A, B); + VERIFY(1 == swap_calls); +} + +// Should use vector specialization for swap. +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + vector A; + vector B; + swap_calls = 0; + swap(A, B); + VERIFY(1 == swap_calls); +} + +// See c++/13658 for background info. +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc new file mode 100644 index 000000000..e86f09416 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc @@ -0,0 +1,132 @@ +// 2005-12-20 Paolo Carlini + +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.2.4.3 vector::swap + +#include +#include +#include + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator my_alloc; + typedef vector my_vector; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1); + + my_vector vec01(alloc01); + size01 = vec01.size(); + my_vector vec02(alloc01); + size02 = vec02.size(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + + my_vector vec03(alloc01); + size01 = vec03.size(); + my_vector vec04(title02, title02 + N2, alloc01); + size02 = vec04.size(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), title02) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + + my_vector vec05(title01, title01 + N1, alloc01); + size01 = vec05.size(); + my_vector vec06(title02, title02 + N2, alloc01); + size02 = vec06.size(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), title02) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), title01) ); + + my_vector vec07(title01, title01 + N1, alloc01); + size01 = vec07.size(); + my_vector vec08(title03, title03 + N3, alloc01); + size02 = vec08.size(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), title03) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), title01) ); + + my_vector vec09(title03, title03 + N3, alloc01); + size01 = vec09.size(); + my_vector vec10(title04, title04 + N4, alloc01); + size02 = vec10.size(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), title04) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), title03) ); + + my_vector vec11(title04, title04 + N4, alloc01); + size01 = vec11.size(); + my_vector vec12(title01, title01 + N1, alloc01); + size02 = vec12.size(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), title01) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), title04) ); + + my_vector vec13(title03, title03 + N3, alloc01); + size01 = vec13.size(); + my_vector vec14(title03, title03 + N3, alloc01); + size02 = vec14.size(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), title03) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc new file mode 100644 index 000000000..1809dd069 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc @@ -0,0 +1,161 @@ +// 2005-12-20 Paolo Carlini + +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.2.4.3 vector::swap + +#include +#include +#include + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator my_alloc; + typedef vector my_vector; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_vector vec01(alloc01); + size01 = vec01.size(); + personality01 = vec01.get_allocator().get_personality(); + my_vector vec02(alloc02); + size02 = vec02.size(); + personality02 = vec02.get_allocator().get_personality(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + VERIFY( vec01.get_allocator().get_personality() == personality02 ); + VERIFY( vec02.get_allocator().get_personality() == personality01 ); + + my_vector vec03(alloc02); + size01 = vec03.size(); + personality01 = vec03.get_allocator().get_personality(); + my_vector vec04(title02, title02 + N2, alloc01); + size02 = vec04.size(); + personality02 = vec04.get_allocator().get_personality(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), title02) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + VERIFY( vec03.get_allocator().get_personality() == personality02 ); + VERIFY( vec04.get_allocator().get_personality() == personality01 ); + + my_vector vec05(title01, title01 + N1, alloc01); + size01 = vec05.size(); + personality01 = vec05.get_allocator().get_personality(); + my_vector vec06(title02, title02 + N2, alloc02); + size02 = vec06.size(); + personality02 = vec06.get_allocator().get_personality(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), title02) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), title01) ); + VERIFY( vec05.get_allocator().get_personality() == personality02 ); + VERIFY( vec06.get_allocator().get_personality() == personality01 ); + + my_vector vec07(title01, title01 + N1, alloc02); + size01 = vec07.size(); + personality01 = vec07.get_allocator().get_personality(); + my_vector vec08(title03, title03 + N3, alloc01); + size02 = vec08.size(); + personality02 = vec08.get_allocator().get_personality(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), title03) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), title01) ); + VERIFY( vec07.get_allocator().get_personality() == personality02 ); + VERIFY( vec08.get_allocator().get_personality() == personality01 ); + + my_vector vec09(title03, title03 + N3, alloc01); + size01 = vec09.size(); + personality01 = vec09.get_allocator().get_personality(); + my_vector vec10(title04, title04 + N4, alloc02); + size02 = vec10.size(); + personality02 = vec10.get_allocator().get_personality(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), title04) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), title03) ); + VERIFY( vec09.get_allocator().get_personality() == personality02 ); + VERIFY( vec10.get_allocator().get_personality() == personality01 ); + + my_vector vec11(title04, title04 + N4, alloc02); + size01 = vec11.size(); + personality01 = vec11.get_allocator().get_personality(); + my_vector vec12(title01, title01 + N1, alloc01); + size02 = vec12.size(); + personality02 = vec12.get_allocator().get_personality(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), title01) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), title04) ); + VERIFY( vec11.get_allocator().get_personality() == personality02 ); + VERIFY( vec12.get_allocator().get_personality() == personality01 ); + + my_vector vec13(title03, title03 + N3, alloc01); + size01 = vec13.size(); + personality01 = vec13.get_allocator().get_personality(); + my_vector vec14(title03, title03 + N3, alloc02); + size02 = vec14.size(); + personality02 = vec14.get_allocator().get_personality(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), title03) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), title03) ); + VERIFY( vec13.get_allocator().get_personality() == personality02 ); + VERIFY( vec14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} -- cgit v1.2.3