Update LOCAL_PATCHES after libsanitizer merge.
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / map / modifiers / merge.cc
blob69b88f877ad2e2a5869383cf0056ce6b02cdfa35
1 // Copyright (C) 2016-2018 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++17" }
20 #include <map>
21 #include <algorithm>
22 #include <testsuite_hooks.h>
24 using test_type = std::map<int, int>;
26 void
27 test01()
29 const test_type c0{ {1, 10}, {2, 20}, {3, 30} };
30 test_type c1 = c0, c2 = c0;
32 c1.merge(c2);
33 VERIFY( c1 == c0 );
34 VERIFY( c2 == c0 );
36 c1.clear();
37 c1.merge(c2);
38 VERIFY( c1 == c0 );
39 VERIFY( c2.empty() );
41 c2.merge(std::move(c1));
42 VERIFY( c1.empty() );
43 VERIFY( c2 == c0 );
46 void
47 test02()
49 const test_type c0{ {1, 10}, {2, 20}, {3, 30} };
50 test_type c1 = c0;
51 std::map<int, int, std::less<>> c2( c0.begin(), c0.end() );
53 c1.merge(c2);
54 VERIFY( c1 == c0 );
55 VERIFY( std::equal(c2.begin(), c2.end(), c0.begin(), c0.end()) );
57 c1.clear();
58 c1.merge(c2);
59 VERIFY( c1 == c0 );
60 VERIFY( c2.empty() );
62 c2.merge(std::move(c1));
63 VERIFY( c1.empty() );
64 VERIFY( std::equal(c2.begin(), c2.end(), c0.begin(), c0.end()) );
67 void
68 test03()
70 const test_type c0{ {1, 10}, {2, 20}, {3, 30} };
71 test_type c1 = c0;
72 std::map<int, int, std::greater<>> c2( c0.begin(), c0.end() );
74 c1.merge(c2);
75 VERIFY( c1 == c0 );
76 VERIFY( std::equal(c2.rbegin(), c2.rend(), c0.begin(), c0.end()) );
78 c1.clear();
79 c1.merge(c2);
80 VERIFY( c1 == c0 );
81 VERIFY( c2.empty() );
83 c2.merge(c1);
84 VERIFY( c1.empty() );
85 VERIFY( std::equal(c2.rbegin(), c2.rend(), c0.begin(), c0.end()) );
87 c1.merge(std::move(c2));
88 VERIFY( c1 == c0 );
89 VERIFY( c2.empty() );
92 void
93 test04()
95 const test_type c0{ {1, 10}, {2, 20}, {3, 30} };
96 test_type c1 = c0;
97 std::multimap<int, int, std::greater<>> c2( c0.begin(), c0.end() );
99 c1.merge(c2);
100 VERIFY( c1 == c0 );
101 VERIFY( std::equal(c2.rbegin(), c2.rend(), c0.begin(), c0.end()) );
103 c1.clear();
104 c1.merge(c2);
105 VERIFY( c1 == c0 );
106 VERIFY( c2.empty() );
108 c2.merge(c1);
109 VERIFY( c1.empty() );
110 VERIFY( std::equal(c2.rbegin(), c2.rend(), c0.begin(), c0.end()) );
112 c1 = c0;
113 c2.merge(c1);
114 VERIFY( c1.empty() );
115 VERIFY( c2.size() == (2 * c0.size()) );
116 VERIFY( std::is_sorted(c2.begin(), c2.end(), c2.value_comp()) );
118 c1.merge(c2);
119 VERIFY( c1 == c0 );
120 VERIFY( std::equal(c2.rbegin(), c2.rend(), c0.begin(), c0.end()) );
122 c1.merge(std::move(c2));
123 VERIFY( c1 == c0 );
124 VERIFY( std::equal(c2.rbegin(), c2.rend(), c0.begin(), c0.end()) );
126 c1.clear();
127 c1.merge(std::move(c2));
128 VERIFY( c1 == c0 );
129 VERIFY( c2.empty() );
133 main()
135 test01();
136 test02();
137 test03();
138 test04();