1 // { dg-do run { target c++23 } }
6 #include <testsuite_allocator.h>
7 #include <testsuite_hooks.h>
9 template<template<class> class Sequence
>
13 std::flat_multiset
<int, std::less
<int>, Sequence
<int>> m
;
14 static_assert( std::ranges::random_access_range
<decltype(m
)> );
23 VERIFY( m
.size() == 7 );
24 VERIFY( std::ranges::equal(m
, (int[]){0, 1, 1, 2, 2, 3, 3}) );
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}) );
39 VERIFY( m
.size() == 2 );
41 VERIFY( m
.size() == 5 );
47 std::flat_multiset
<int, std::greater
<int>> m
;
48 static_assert( std::ranges::random_access_range
<decltype(m
)> );
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 );
77 VERIFY( it
== m
.end() );
79 VERIFY( it
== m
.end()-1 );
87 m
.erase(m
.end()-2, m
.end());
88 VERIFY( std::ranges::equal(m
, (int[]){3}) );
93 erase_if(m
, [](const auto& k
) { return k
< 5 || k
> 5; });
94 VERIFY( std::ranges::equal(m
, (int[]){5}) );
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 );
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}) );
134 test01
<std::vector
>();
135 test01
<std::deque
>();