c++: Speed up compilation of large char array initializers when not using #embed
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multiset / operations / 1.cc
blob562420a0db2ad5cf22f81d6200a37af134a61459
1 // Copyright (C) 2021-2025 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-do run { target c++20 } }
20 #include <unordered_set>
21 #include <testsuite_hooks.h>
23 struct Equal
25 typedef void is_transparent;
27 bool operator()(int i, long l) const { return i == l; }
28 bool operator()(long l, int i) const { return l == i; }
29 bool operator()(int i, int j) const { ++count; return i == j; }
31 static int count;
34 int Equal::count = 0;
36 struct Hash
38 typedef void is_transparent;
40 std::size_t operator()(int i) const { ++count; return i; }
41 std::size_t operator()(long l) const { return l; }
43 static int count;
46 int Hash::count = 0;
48 using test_type = std::unordered_multiset<int, Hash, Equal>;
50 test_type x{ 1, 3, 3, 5 };
51 const test_type& cx = x;
53 void
54 test01()
56 Hash::count = 0;
57 Equal::count = 0;
59 VERIFY( x.contains(1L) );
61 auto it = x.find(1L);
62 VERIFY( it != x.end() && *it == 1 );
63 it = x.find(2L);
64 VERIFY( it == x.end() );
66 auto cit = cx.find(3L);
67 VERIFY( cit != cx.end() && *cit == 3 );
68 cit = cx.find(2L);
69 VERIFY( cit == cx.end() );
71 VERIFY( Hash::count == 0 );
72 VERIFY( Equal::count == 0 );
74 static_assert(std::is_same<decltype(it), test_type::iterator>::value,
75 "find returns iterator");
76 static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
77 "const find returns const_iterator");
80 void
81 test02()
83 Hash::count = 0;
84 Equal::count = 0;
86 auto n = x.count(1L);
87 VERIFY( n == 1 );
88 n = x.count(2L);
89 VERIFY( n == 0 );
91 auto cn = cx.count(3L);
92 VERIFY( cn == 2 );
93 cn = cx.count(2L);
94 VERIFY( cn == 0 );
96 VERIFY( Hash::count == 0 );
97 VERIFY( Equal::count == 0 );
100 void
101 test03()
103 Hash::count = 0;
104 Equal::count = 0;
106 auto it = x.equal_range(1L);
107 VERIFY( it.first != it.second && *it.first == 1 );
108 it = x.equal_range(2L);
109 VERIFY( it.first == it.second && it.first == x.end() );
111 auto cit = cx.equal_range(3L);
112 VERIFY( cit.first != cit.second && *cit.first == 3 );
113 VERIFY( std::distance(cit.first, cit.second) == 2 );
114 cit = cx.equal_range(2L);
115 VERIFY( cit.first == cit.second && cit.first == cx.end() );
117 VERIFY( Hash::count == 0 );
118 VERIFY( Equal::count == 0 );
120 using pair = std::pair<test_type::iterator, test_type::iterator>;
121 static_assert(std::is_same<decltype(it), pair>::value,
122 "equal_range returns pair<iterator, iterator>");
123 using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
124 static_assert(std::is_same<decltype(cit), cpair>::value,
125 "const equal_range returns pair<const_iterator, const_iterator>");
130 main()
132 test01();
133 test02();
134 test03();