diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/23_containers/multimap/modifiers | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
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.
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/multimap/modifiers')
10 files changed, 919 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/47628.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/47628.cc new file mode 100644 index 000000000..c45013a12 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/47628.cc @@ -0,0 +1,46 @@ +// 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 +// <http://www.gnu.org/licenses/>. +// + +// { dg-do compile } + +#include <map> + +struct Key +{ + Key() { } + + Key(const Key&) { } + + template<typename T> + Key(const T&) + { } + + bool operator<(const Key&) const; +}; + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +// libstdc++/47628 +void f() +{ + typedef std::multimap<Key, int> MMap; + MMap mm; + mm.insert(MMap::value_type()); + MMap::iterator i = mm.begin(); + mm.erase(i); +} +#endif diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/51142.cc new file mode 100644 index 000000000..ee687f77c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/51142.cc @@ -0,0 +1,38 @@ +// 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 +// <http://www.gnu.org/licenses/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <map> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator<(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::multimap<X, int>& s, X x) +{ + std::multimap<X, int>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc new file mode 100644 index 000000000..f07e97d7d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(2, rvalstruct(3))); + m.insert(Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( (i1->second).val == 3 && (i2->second).val == 7 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc new file mode 100644 index 000000000..56453cade --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( (i1->second).val == 3 && (i2->second).val == 7 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc new file mode 100644 index 000000000..e89251962 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc @@ -0,0 +1,140 @@ +// 2006-01-07 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 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 +// <http://www.gnu.org/licenses/>. + +// 23.3.2 Class template multimap + +#include <map> +#include <testsuite_hooks.h> + +// libstdc++/22102 +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::multimap<int, int> Mmap; + typedef Mmap::value_type value_type; + typedef Mmap::iterator iterator; + + Mmap mm1; + + const iterator it1 = mm1.insert(value_type(0, 0)); + const iterator it2 = mm1.insert(value_type(1, 1)); + const iterator it3 = mm1.insert(value_type(2, 2)); + + const value_type vt1(2, 1); + const iterator it4 = mm1.insert(it1, vt1); + iterator it5 = it4; + iterator it6 = it4; + VERIFY( mm1.size() == 4 ); + VERIFY( *it4 == vt1 ); + VERIFY( ++it5 == it3 ); + VERIFY( --it6 == it2 ); + VERIFY( *it5 == *it3 ); + VERIFY( *it6 == *it2 ); + + const value_type vt2(2, 0); + const iterator it7 = mm1.insert(mm1.begin(), vt2); + iterator it8 = it7; + iterator it9 = it7; + VERIFY( mm1.size() == 5 ); + VERIFY( *it7 == vt2 ); + VERIFY( ++it8 == it4 ); + VERIFY( --it9 == it2 ); + VERIFY( *it8 == *it4 ); + VERIFY( *it9 == *it2 ); + + const value_type vt3(2, -1); + const iterator it10 = mm1.insert(it1, vt3); + iterator it11 = it10; + iterator it12 = it10; + VERIFY( mm1.size() == 6 ); + VERIFY( *it10 == vt3 ); + VERIFY( ++it11 == it7 ); + VERIFY( --it12 == it2 ); + VERIFY( *it11 == *it7 ); + VERIFY( *it12 == *it2 ); + + const value_type vt4(0, 1); + const iterator it13 = mm1.insert(it10, vt4); + iterator it14 = it13; + iterator it15 = it13; + VERIFY( mm1.size() == 7 ); + VERIFY( *it13 == vt4 ); + VERIFY( ++it14 == it2 ); + VERIFY( --it15 == it1 ); + VERIFY( *it14 == *it2 ); + VERIFY( *it15 == *it1 ); + + const value_type vt5(1, 0); + const iterator it16 = mm1.insert(it13, vt5); + iterator it17 = it16; + iterator it18 = it16; + VERIFY( mm1.size() == 8 ); + VERIFY( *it16 == vt5 ); + VERIFY( ++it17 == it2 ); + VERIFY( --it18 == it13 ); + VERIFY( *it17 == *it2 ); + VERIFY( *it18 == *it13 ); + + const value_type vt6(0, -1); + const iterator it19 = mm1.insert(it1, vt6); + iterator it20 = it19; + VERIFY( mm1.size() == 9 ); + VERIFY( *it19 == vt6 ); + VERIFY( it19 == mm1.begin() ); + VERIFY( ++it20 == it1 ); + VERIFY( *it20 == *it1 ); + + const value_type vt7(3, 3); + const iterator it21 = mm1.insert(it19, vt7); + iterator it22 = it21; + iterator it23 = it21; + VERIFY( mm1.size() == 10 ); + VERIFY( *it21 == vt7 ); + VERIFY( ++it22 == mm1.end() ); + VERIFY( --it23 == it3 ); + VERIFY( *it23 == *it3 ); + + const value_type vt8(2, 3); + const iterator it24 = mm1.insert(mm1.end(), vt8); + iterator it25 = it24; + iterator it26 = it24; + VERIFY( mm1.size() == 11 ); + VERIFY( *it24 == vt8 ); + VERIFY( ++it25 == it21 ); + VERIFY( --it26 == it3 ); + VERIFY( *it25 == *it21 ); + VERIFY( *it26 == *it3 ); + + const value_type vt9(3, 2); + const iterator it27 = mm1.insert(it3, vt9); + iterator it28 = it27; + iterator it29 = it27; + VERIFY( mm1.size() == 12 ); + VERIFY( *it27 == vt9 ); + VERIFY( ++it28 == it21 ); + VERIFY( --it29 == it24 ); + VERIFY( *it28 == *it21 ); + VERIFY( *it29 == *it24 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc new file mode 100644 index 000000000..dddd8c885 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(m.begin(), Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i0 = m.insert(m.begin(), Pair(2, rvalstruct(3))); + m.insert(i0, Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( (i1->second).val == 7 && (i2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc new file mode 100644 index 000000000..a53852cc1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(m.begin(), + Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i0 = m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(i0, Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( (i1->second).val == 7 && (i2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc new file mode 100644 index 000000000..2b9a7442c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc @@ -0,0 +1,65 @@ +// 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 +// <http://www.gnu.org/licenses/>. + +#include <map> +#include <testsuite_hooks.h> + +struct T { int i; }; + +// T must be LessThanComparable to pass concept-checks +bool operator<(T l, T r) { return l.i < r.i; } + +int swap_calls; + +namespace std +{ + template<> + void + multimap<T, int>::swap(multimap<T, int>&) + { ++swap_calls; } +} + +// Should use multimap specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::multimap<T, int> A; + std::multimap<T, int> B; + swap_calls = 0; + std::swap(A, B); + VERIFY(1 == swap_calls); +} + +// Should use multimap specialization for swap. +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + multimap<T, int> A; + multimap<T, int> 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/multimap/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc new file mode 100644 index 000000000..463409b6d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc @@ -0,0 +1,146 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// 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 +// <http://www.gnu.org/licenses/>. + +// 23.3.2 multimap::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef multimap<char, int, less<char>, my_alloc> my_mmap; + + 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); + + multimap<char, int> mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + multimap<char, int> mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + multimap<char, int> mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + multimap<char, int> mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + my_mmap::size_type size01, size02; + + my_alloc alloc01(1); + + my_mmap mmap01(less<char>(), alloc01); + size01 = mmap01.size(); + my_mmap mmap02(less<char>(), alloc01); + size02 = mmap02.size(); + + mmap01.swap(mmap02); + VERIFY( mmap01.size() == size02 ); + VERIFY( mmap01.empty() ); + VERIFY( mmap02.size() == size01 ); + VERIFY( mmap02.empty() ); + + my_mmap mmap03(less<char>(), alloc01); + size01 = mmap03.size(); + my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap04.size(); + + mmap03.swap(mmap04); + VERIFY( mmap03.size() == size02 ); + VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) ); + VERIFY( mmap04.size() == size01 ); + VERIFY( mmap04.empty() ); + + my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap05.size(); + my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap06.size(); + + mmap05.swap(mmap06); + VERIFY( mmap05.size() == size02 ); + VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) ); + VERIFY( mmap06.size() == size01 ); + VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) ); + + my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap07.size(); + my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap08.size(); + + mmap07.swap(mmap08); + VERIFY( mmap07.size() == size02 ); + VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) ); + VERIFY( mmap08.size() == size01 ); + VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) ); + + my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap09.size(); + my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01); + size02 = mmap10.size(); + + mmap09.swap(mmap10); + VERIFY( mmap09.size() == size02 ); + VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) ); + VERIFY( mmap10.size() == size01 ); + VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) ); + + my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01); + size01 = mmap11.size(); + my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size02 = mmap12.size(); + + mmap11.swap(mmap12); + VERIFY( mmap11.size() == size02 ); + VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) ); + VERIFY( mmap12.size() == size01 ); + VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) ); + + my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap13.size(); + my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap14.size(); + + mmap13.swap(mmap14); + VERIFY( mmap13.size() == size02 ); + VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) ); + VERIFY( mmap14.size() == size01 ); + VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc new file mode 100644 index 000000000..6f553df0e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc @@ -0,0 +1,175 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// 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 +// <http://www.gnu.org/licenses/>. + +// 23.3.2 multimap::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef multimap<char, int, less<char>, my_alloc> my_mmap; + + 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); + + multimap<char, int> mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + multimap<char, int> mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + multimap<char, int> mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + multimap<char, int> mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + my_mmap::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_mmap mmap01(less<char>(), alloc01); + size01 = mmap01.size(); + personality01 = mmap01.get_allocator().get_personality(); + my_mmap mmap02(less<char>(), alloc02); + size02 = mmap02.size(); + personality02 = mmap02.get_allocator().get_personality(); + + mmap01.swap(mmap02); + VERIFY( mmap01.size() == size02 ); + VERIFY( mmap01.empty() ); + VERIFY( mmap02.size() == size01 ); + VERIFY( mmap02.empty() ); + VERIFY( mmap01.get_allocator().get_personality() == personality02 ); + VERIFY( mmap02.get_allocator().get_personality() == personality01 ); + + my_mmap mmap03(less<char>(), alloc02); + size01 = mmap03.size(); + personality01 = mmap03.get_allocator().get_personality(); + my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap04.size(); + personality02 = mmap04.get_allocator().get_personality(); + + mmap03.swap(mmap04); + VERIFY( mmap03.size() == size02 ); + VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) ); + VERIFY( mmap04.size() == size01 ); + VERIFY( mmap04.empty() ); + VERIFY( mmap03.get_allocator().get_personality() == personality02 ); + VERIFY( mmap04.get_allocator().get_personality() == personality01 ); + + my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap05.size(); + personality01 = mmap05.get_allocator().get_personality(); + my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc02); + size02 = mmap06.size(); + personality02 = mmap06.get_allocator().get_personality(); + + mmap05.swap(mmap06); + VERIFY( mmap05.size() == size02 ); + VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) ); + VERIFY( mmap06.size() == size01 ); + VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) ); + VERIFY( mmap05.get_allocator().get_personality() == personality02 ); + VERIFY( mmap06.get_allocator().get_personality() == personality01 ); + + my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc02); + size01 = mmap07.size(); + personality01 = mmap07.get_allocator().get_personality(); + my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap08.size(); + personality02 = mmap08.get_allocator().get_personality(); + + mmap07.swap(mmap08); + VERIFY( mmap07.size() == size02 ); + VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) ); + VERIFY( mmap08.size() == size01 ); + VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) ); + VERIFY( mmap07.get_allocator().get_personality() == personality02 ); + VERIFY( mmap08.get_allocator().get_personality() == personality01 ); + + my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap09.size(); + personality01 = mmap09.get_allocator().get_personality(); + my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc02); + size02 = mmap10.size(); + personality02 = mmap10.get_allocator().get_personality(); + + mmap09.swap(mmap10); + VERIFY( mmap09.size() == size02 ); + VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) ); + VERIFY( mmap10.size() == size01 ); + VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) ); + VERIFY( mmap09.get_allocator().get_personality() == personality02 ); + VERIFY( mmap10.get_allocator().get_personality() == personality01 ); + + my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc02); + size01 = mmap11.size(); + personality01 = mmap11.get_allocator().get_personality(); + my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size02 = mmap12.size(); + personality02 = mmap12.get_allocator().get_personality(); + + mmap11.swap(mmap12); + VERIFY( mmap11.size() == size02 ); + VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) ); + VERIFY( mmap12.size() == size01 ); + VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) ); + VERIFY( mmap11.get_allocator().get_personality() == personality02 ); + VERIFY( mmap12.get_allocator().get_personality() == personality01 ); + + my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap13.size(); + personality01 = mmap13.get_allocator().get_personality(); + my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc02); + size02 = mmap14.size(); + personality02 = mmap14.get_allocator().get_personality(); + + mmap13.swap(mmap14); + VERIFY( mmap13.size() == size02 ); + VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) ); + VERIFY( mmap14.size() == size01 ); + VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) ); + VERIFY( mmap13.get_allocator().get_personality() == personality02 ); + VERIFY( mmap14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} |