1 // { dg-do run { target c++23 } }
6 #include <testsuite_allocator.h>
7 #include <testsuite_hooks.h>
9 template<template<typename
> class KeyContainer
, template<typename
> class MappedContainer
>
13 std::flat_multimap
<int, int, std::less
<int>, KeyContainer
<int>, MappedContainer
<int>> m
;
14 static_assert( std::ranges::random_access_range
<decltype(m
)> );
23 VERIFY( m
.size() == 7 );
24 VERIFY( std::ranges::equal(m
.keys(), (int[]){0, 1, 1, 2, 2, 3, 3}) );
25 VERIFY( std::ranges::equal(m
.values(), (int[]){0, -1, -4, -2, -5, -3, -6}) );
28 m
.insert(m
.begin(), {0, 0});
29 m
.insert(m
.begin(), {1,-1});
30 m
.insert(m
.begin(), {2,-2});
31 m
.insert(m
.begin(), {3,-3});
32 m
.insert(m
.begin(), {1,-4});
33 m
.insert(m
.begin(), {2,-5});
34 m
.insert(m
.begin(), {3,-6});
35 m
.insert(m
.begin(), {0,-7});
36 VERIFY( std::ranges::equal(m
.keys(), (int[]){0, 0, 1, 1, 2, 2, 3, 3}) );
37 VERIFY( std::ranges::equal(m
.values(), (int[]){-7, 0, -4, -1, -5, -2, -6, -3}) );
41 VERIFY( m
.size() == 2 );
42 m
.insert({{11,2},{12,3},{11,4}});
43 VERIFY( m
.size() == 5 );
44 VERIFY( m
.end()[-1] == std::pair(12,3) );
50 std::flat_multimap
<int, int, std::greater
<int>> m
;
51 static_assert( std::ranges::random_access_range
<decltype(m
)> );
53 auto r
= m
.insert({1,-1});
54 VERIFY( r
->first
== 1 && r
->second
== -1 );
56 VERIFY( r
->first
== 2 && r
->second
== -2 );
58 VERIFY( r
->first
== 3 && r
->second
== -3 );
60 VERIFY( r
->first
== 1 && r
->second
== -4 );
62 VERIFY( r
->first
== 2 && r
->second
== -5 );
64 VERIFY( r
->first
== 3 && r
->second
== -6 );
65 VERIFY( m
.size() == 6 );
66 VERIFY( std::ranges::equal(m
.keys(), (int[]){3, 3, 2, 2, 1, 1}) );
67 VERIFY( std::ranges::equal(m
.values(), (int[]){-3, -6, -2, -5, -1, -4}) );
69 VERIFY( m
.contains(3) && !m
.contains(7) );
70 VERIFY( m
.count(3) == 2 );
76 std::flat_multimap
<int, int> m
;
77 m
= {std::pair(1, 2), {3, 4}, {5, 6}};
78 m
.insert({std::pair(7, 8), {9, 10}});
81 VERIFY( it
== m
.end() );
83 VERIFY( it
->second
== 10 );
91 m
.erase(m
.end()-2, m
.end());
92 VERIFY( std::ranges::equal(m
, (std::pair
<int, int>[]){{3, 4}}) );
97 erase_if(m
, [](const auto& x
) { auto [k
, v
] = x
; return k
< 5 || k
> 5; });
98 VERIFY( std::ranges::equal(m
, (std::pair
<int, int>[]){{5, 6}}) );
104 using vector
= std::vector
<int, __gnu_test::uneq_allocator
<int>>;
105 vector v1
= {1, 2, 3};
106 vector v2
= {4, 5, 6};
107 __gnu_test::uneq_allocator
<int> alloc(42);
109 using flat_multimap
= std::flat_multimap
<int, int, std::less
<int>, vector
, vector
>;
110 flat_multimap
m1(alloc
);
111 VERIFY( m1
.keys().get_allocator().get_personality() == 42 );
112 VERIFY( m1
.values().get_allocator().get_personality() == 42 );
114 flat_multimap
m2(v1
, v2
, alloc
);
115 VERIFY( m2
.keys().get_allocator().get_personality() == 42 );
116 VERIFY( m2
.values().get_allocator().get_personality() == 42 );
118 flat_multimap
m3(std::sorted_equivalent_t
{}, v1
, v2
, alloc
);
119 VERIFY( m2
.keys().get_allocator().get_personality() == 42 );
120 VERIFY( m2
.values().get_allocator().get_personality() == 42 );
122 alloc
= __gnu_test::uneq_allocator
<int>(43);
123 flat_multimap
m4(m2
, alloc
);
124 VERIFY( m4
.keys().get_allocator().get_personality() == 43 );
125 VERIFY( m4
.values().get_allocator().get_personality() == 43 );
127 alloc
= __gnu_test::uneq_allocator
<int>(44);
128 flat_multimap
m5(std::move(m4
), alloc
);
129 VERIFY( m5
.keys().get_allocator().get_personality() == 44 );
130 VERIFY( m5
.values().get_allocator().get_personality() == 44 );
136 std::vector
<std::pair
<int, int>> v
= {{2, -2}, {3,-3}, {1,-1}, {5,-5}, {4,-4}, {3,3}};
137 std::flat_multimap
<int, int> m
= {std::from_range
, v
};
138 VERIFY( std::ranges::equal(m
| std::views::keys
, (int[]){1, 2, 3, 3, 4, 5}) );
139 VERIFY( std::ranges::equal(m
| std::views::values
, (int[]){-1, -2, -3, 3, -4, -5}) );
145 test01
<std::vector
, std::vector
>();
146 test01
<std::deque
, std::deque
>();
147 test01
<std::vector
, std::deque
>();
148 test01
<std::deque
, std::vector
>();