d: Merge dmd, druntime c7902293d7, phobos 03aeafd20
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / flat_multiset / 1.cc
blob82958f7939bc04eea3ea279d56132a73b54016d0
1 // { dg-do run { target c++23 } }
3 #include <flat_set>
4 #include <deque>
5 #include <vector>
6 #include <testsuite_allocator.h>
7 #include <testsuite_hooks.h>
9 template<template<class> class Sequence>
10 void
11 test01()
13 std::flat_multiset<int, std::less<int>, Sequence<int>> m;
14 static_assert( std::ranges::random_access_range<decltype(m)> );
16 m.insert(1);
17 m.insert(2);
18 m.insert(3);
19 m.insert(1);
20 m.insert(2);
21 m.insert(3);
22 m.insert(0);
23 VERIFY( m.size() == 7 );
24 VERIFY( std::ranges::equal(m, (int[]){0, 1, 1, 2, 2, 3, 3}) );
26 m.clear();
27 m.insert(m.begin(), 0);
28 m.insert(m.begin(), 1);
29 m.insert(m.begin(), 2);
30 m.insert(m.begin(), 3);
31 m.insert(m.begin(), 1);
32 m.insert(m.begin(), 2);
33 m.insert(m.begin(), 3);
34 m.insert(m.begin(), 0);
35 VERIFY( std::ranges::equal(m, (int[]){0, 0, 1, 1, 2, 2, 3, 3}) );
37 m.clear();
38 m = {10,10};
39 VERIFY( m.size() == 2 );
40 m.insert({11,12,11});
41 VERIFY( m.size() == 5 );
44 void
45 test02()
47 std::flat_multiset<int, std::greater<int>> m;
48 static_assert( std::ranges::random_access_range<decltype(m)> );
50 auto r = m.insert(1);
51 VERIFY( *r == 1 );
52 r = m.insert(2);
53 VERIFY( *r == 2 );
54 r = m.insert(3);
55 VERIFY( *r == 3 );
56 r = m.insert(1);
57 VERIFY( *r == 1 );
58 r = m.insert(2);
59 VERIFY( *r == 2 );
60 r = m.insert(3);
61 VERIFY( *r == 3 );
62 VERIFY( m.size() == 6 );
63 VERIFY( std::ranges::equal(m, (int[]){3, 3, 2, 2, 1, 1}) );
65 VERIFY( m.contains(3) && !m.contains(7) );
66 VERIFY( m.count(3) == 2 );
69 void
70 test03()
72 std::flat_set<int> m;
73 m = {1, 3, 5};
74 m.insert({7, 9});
76 auto it = m.find(0);
77 VERIFY( it == m.end() );
78 it = m.find(9);
79 VERIFY( it == m.end()-1 );
81 const auto n = m;
82 VERIFY( m == m );
83 VERIFY( m == n );
85 m.erase(m.begin());
86 m.erase(5);
87 m.erase(m.end()-2, m.end());
88 VERIFY( std::ranges::equal(m, (int[]){3}) );
89 VERIFY( m != n );
90 VERIFY( n < m );
92 m = n;
93 erase_if(m, [](const auto& k) { return k < 5 || k > 5; });
94 VERIFY( std::ranges::equal(m, (int[]){5}) );
97 void
98 test04()
100 using vector = std::vector<int, __gnu_test::uneq_allocator<int>>;
101 vector v = {1, 2, 3};
102 __gnu_test::uneq_allocator<int> alloc(42);
104 using flat_multiset = std::flat_multiset<int, std::less<int>, vector>;
105 flat_multiset m1(alloc);
106 VERIFY( std::move(m1).extract().get_allocator().get_personality() == 42 );
108 flat_multiset m2(v, alloc);
109 VERIFY( std::move(m2).extract().get_allocator().get_personality() == 42 );
111 flat_multiset m3(std::sorted_equivalent_t{}, v, alloc);
112 VERIFY( std::move(m3).extract().get_allocator().get_personality() == 42 );
114 alloc = __gnu_test::uneq_allocator<int>(43);
115 flat_multiset m4(m3, alloc);
116 VERIFY( std::move(m4).extract().get_allocator().get_personality() == 43 );
118 alloc = __gnu_test::uneq_allocator<int>(44);
119 flat_multiset m5(std::move(m4), alloc);
120 VERIFY( std::move(m5).extract().get_allocator().get_personality() == 44 );
123 void
124 test05()
126 std::vector<int> v = {2, 3, 1, 5, 4, 3};
127 std::flat_multiset<int, std::less<>, std::deque<int>> m = {std::from_range, v};
128 VERIFY( std::ranges::equal(m, (int[]){1, 2, 3, 3, 4, 5}) );
132 main()
134 test01<std::vector>();
135 test01<std::deque>();
136 test02();
137 test03();
138 test04();
139 test05();