Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / containers / associative / map / map.modifiers / insert_rv.pass.cpp
blobafb5bba86fd3ee26eb70a9ec596852ba653772ba
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <map>
13 // class map
15 // pair<iterator, bool> insert( value_type&& v); // C++17 and later
16 // template <class P>
17 // pair<iterator, bool> insert(P&& p);
19 #include <map>
20 #include <cassert>
22 #include "MoveOnly.h"
23 #include "min_allocator.h"
24 #include "test_macros.h"
26 template <class Container, class Pair>
27 void do_insert_rv_test()
29 typedef Container M;
30 typedef Pair P;
31 typedef std::pair<typename M::iterator, bool> R;
32 M m;
33 R r = m.insert(P(2, 2));
34 assert(r.second);
35 assert(r.first == m.begin());
36 assert(m.size() == 1);
37 assert(r.first->first == 2);
38 assert(r.first->second == 2);
40 r = m.insert(P(1, 1));
41 assert(r.second);
42 assert(r.first == m.begin());
43 assert(m.size() == 2);
44 assert(r.first->first == 1);
45 assert(r.first->second == 1);
47 r = m.insert(P(3, 3));
48 assert(r.second);
49 assert(r.first == std::prev(m.end()));
50 assert(m.size() == 3);
51 assert(r.first->first == 3);
52 assert(r.first->second == 3);
54 r = m.insert(P(3, 3));
55 assert(!r.second);
56 assert(r.first == std::prev(m.end()));
57 assert(m.size() == 3);
58 assert(r.first->first == 3);
59 assert(r.first->second == 3);
62 int main(int, char**)
64 do_insert_rv_test<std::map<int, MoveOnly>, std::pair<int, MoveOnly>>();
65 do_insert_rv_test<std::map<int, MoveOnly>, std::pair<const int, MoveOnly>>();
68 typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
69 typedef std::pair<int, MoveOnly> P;
70 typedef std::pair<const int, MoveOnly> CP;
71 do_insert_rv_test<M, P>();
72 do_insert_rv_test<M, CP>();
75 typedef std::map<int, MoveOnly> M;
76 typedef std::pair<M::iterator, bool> R;
77 M m;
78 R r = m.insert({2, MoveOnly(2)});
79 assert(r.second);
80 assert(r.first == m.begin());
81 assert(m.size() == 1);
82 assert(r.first->first == 2);
83 assert(r.first->second == 2);
85 r = m.insert({1, MoveOnly(1)});
86 assert(r.second);
87 assert(r.first == m.begin());
88 assert(m.size() == 2);
89 assert(r.first->first == 1);
90 assert(r.first->second == 1);
92 r = m.insert({3, MoveOnly(3)});
93 assert(r.second);
94 assert(r.first == std::prev(m.end()));
95 assert(m.size() == 3);
96 assert(r.first->first == 3);
97 assert(r.first->second == 3);
99 r = m.insert({3, MoveOnly(3)});
100 assert(!r.second);
101 assert(r.first == std::prev(m.end()));
102 assert(m.size() == 3);
103 assert(r.first->first == 3);
104 assert(r.first->second == 3);
107 return 0;