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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <map> |
10 | |
11 | // class map |
12 | |
13 | // pair<iterator, bool> insert(const value_type& v); |
14 | |
15 | #include <map> |
16 | #include <cassert> |
17 | |
18 | #include "test_macros.h" |
19 | #include "min_allocator.h" |
20 | |
21 | template <class Container> |
22 | void do_insert_cv_test() { |
23 | typedef Container M; |
24 | typedef std::pair<typename M::iterator, bool> R; |
25 | typedef typename M::value_type VT; |
26 | M m; |
27 | |
28 | const VT v1(2, 2.5); |
29 | R r = m.insert(v1); |
30 | assert(r.second); |
31 | assert(r.first == m.begin()); |
32 | assert(m.size() == 1); |
33 | assert(r.first->first == 2); |
34 | assert(r.first->second == 2.5); |
35 | |
36 | const VT v2(1, 1.5); |
37 | r = m.insert(v2); |
38 | assert(r.second); |
39 | assert(r.first == m.begin()); |
40 | assert(m.size() == 2); |
41 | assert(r.first->first == 1); |
42 | assert(r.first->second == 1.5); |
43 | |
44 | const VT v3(3, 3.5); |
45 | r = m.insert(v3); |
46 | assert(r.second); |
47 | assert(r.first == std::prev(m.end())); |
48 | assert(m.size() == 3); |
49 | assert(r.first->first == 3); |
50 | assert(r.first->second == 3.5); |
51 | |
52 | const VT v4(3, 4.5); |
53 | r = m.insert(v4); |
54 | assert(!r.second); |
55 | assert(r.first == std::prev(m.end())); |
56 | assert(m.size() == 3); |
57 | assert(r.first->first == 3); |
58 | assert(r.first->second == 3.5); |
59 | } |
60 | |
61 | int main(int, char**) { |
62 | do_insert_cv_test<std::map<int, double> >(); |
63 | #if TEST_STD_VER >= 11 |
64 | { |
65 | typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; |
66 | do_insert_cv_test<M>(); |
67 | } |
68 | #endif |
69 | |
70 | return 0; |
71 | } |
72 | |