@@ -42,18 +42,100 @@ static_assert(!CanEmplaceHint<Map, int, double>);
4242#endif
4343
4444template <class KeyContainer , class ValueContainer >
45- void test_simple () {
45+ void test () {
4646 using Key = typename KeyContainer::value_type;
4747 using Value = typename ValueContainer::value_type;
4848 using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
4949 using R = M::iterator;
50- M m;
51- ASSERT_SAME_TYPE (decltype (m.emplace_hint (m.cbegin ())), R);
52- R r = m.emplace_hint (m.end (), typename M::value_type (2 , 3.5 ));
53- assert (r == m.begin ());
54- assert (m.size () == 1 );
55- assert (m.begin ()->first == 2 );
56- assert (m.begin ()->second == 3.5 );
50+ {
51+ // was empty
52+ M m;
53+ std::same_as<R> decltype (auto ) r = m.emplace_hint (m.end (), typename M::value_type (2 , 3.5 ));
54+ assert (r == m.begin ());
55+ assert (m.size () == 1 );
56+ assert (r->first == 2 );
57+ assert (r->second == 3.5 );
58+ }
59+ {
60+ // hints correct at the begin
61+ M m = {{3 , 3.0 }, {4 , 4.0 }};
62+ auto hint = m.begin ();
63+ std::same_as<R> decltype (auto ) r = m.emplace_hint (hint, typename M::value_type (2 , 2.0 ));
64+ assert (r == m.begin ());
65+ assert (m.size () == 3 );
66+ assert (r->first == 2 );
67+ assert (r->second == 2.0 );
68+ }
69+ {
70+ // hints correct in the middle
71+ M m = {{0 , 0.0 }, {1 , 1.0 }, {3 , 3.0 }, {4 , 4.0 }};
72+ auto hint = m.begin () + 2 ;
73+ std::same_as<R> decltype (auto ) r = m.emplace_hint (hint, typename M::value_type (2 , 2.0 ));
74+ assert (r == m.begin () + 2 );
75+ assert (m.size () == 5 );
76+ assert (r->first == 2 );
77+ assert (r->second == 2.0 );
78+ }
79+ {
80+ // hints correct at the end
81+ M m = {{0 , 0.0 }, {1 , 1.0 }};
82+ auto hint = m.end ();
83+ std::same_as<R> decltype (auto ) r = m.emplace_hint (hint, typename M::value_type (2 , 2.0 ));
84+ assert (r == m.begin () + 2 );
85+ assert (m.size () == 3 );
86+ assert (r->first == 2 );
87+ assert (r->second == 2.0 );
88+ }
89+ {
90+ // hints correct but key already exists
91+ M m = {{0 , 0.0 }, {1 , 1.0 }, {2 , 1.9 }, {3 , 3.0 }, {4 , 4.0 }};
92+ auto hint = m.begin () + 2 ;
93+ std::same_as<R> decltype (auto ) r = m.emplace_hint (hint, typename M::value_type (2 , 2.0 ));
94+ assert (r == m.begin () + 2 );
95+ assert (m.size () == 5 );
96+ assert (r->first == 2 );
97+ assert (r->second == 1.9 );
98+ }
99+ {
100+ // hints incorrectly at the begin
101+ M m = {{1 , 1.0 }, {4 , 4.0 }};
102+ auto hint = m.begin ();
103+ std::same_as<R> decltype (auto ) r = m.emplace_hint (hint, typename M::value_type (2 , 2.0 ));
104+ assert (r == m.begin () + 1 );
105+ assert (m.size () == 3 );
106+ assert (r->first == 2 );
107+ assert (r->second == 2.0 );
108+ }
109+ {
110+ // hints incorrectly in the middle
111+ M m = {{0 , 0.0 }, {1 , 1.0 }, {3 , 3.0 }, {4 , 4.0 }};
112+ auto hint = m.begin () + 1 ;
113+ std::same_as<R> decltype (auto ) r = m.emplace_hint (hint, typename M::value_type (2 , 2.0 ));
114+ assert (r == m.begin () + 2 );
115+ assert (m.size () == 5 );
116+ assert (r->first == 2 );
117+ assert (r->second == 2.0 );
118+ }
119+ {
120+ // hints incorrectly at the end
121+ M m = {{0 , 0.0 }, {3 , 3.0 }};
122+ auto hint = m.end ();
123+ std::same_as<R> decltype (auto ) r = m.emplace_hint (hint, typename M::value_type (2 , 2.0 ));
124+ assert (r == m.begin () + 1 );
125+ assert (m.size () == 3 );
126+ assert (r->first == 2 );
127+ assert (r->second == 2.0 );
128+ }
129+ {
130+ // hints incorrect and key already exists
131+ M m = {{0 , 0.0 }, {1 , 1.0 }, {2 , 1.9 }, {3 , 3.0 }, {4 , 4.0 }};
132+ auto hint = m.begin ();
133+ std::same_as<R> decltype (auto ) r = m.emplace_hint (hint, typename M::value_type (2 , 2.0 ));
134+ assert (r == m.begin () + 2 );
135+ assert (m.size () == 5 );
136+ assert (r->first == 2 );
137+ assert (r->second == 1.9 );
138+ }
57139}
58140
59141template <class KeyContainer , class ValueContainer >
@@ -81,10 +163,10 @@ void test_emplaceable() {
81163}
82164
83165int main (int , char **) {
84- test_simple <std::vector<int >, std::vector<double >>();
85- test_simple <std::deque<int >, std::vector<double >>();
86- test_simple <MinSequenceContainer<int >, MinSequenceContainer<double >>();
87- test_simple <std::vector<int , min_allocator<int >>, std::vector<double , min_allocator<double >>>();
166+ test <std::vector<int >, std::vector<double >>();
167+ test <std::deque<int >, std::vector<double >>();
168+ test <MinSequenceContainer<int >, MinSequenceContainer<double >>();
169+ test <std::vector<int , min_allocator<int >>, std::vector<double , min_allocator<double >>>();
88170
89171 test_emplaceable<std::vector<int >, std::vector<Emplaceable>>();
90172 test_emplaceable<std::deque<int >, std::vector<Emplaceable>>();
0 commit comments