1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <map>
11 
12 // class map
13 
14 // pair<iterator, bool> insert(const value_type& v);
15 
16 #include <map>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "min_allocator.h"
21 
22 template <class Container>
do_insert_cv_test()23 void do_insert_cv_test()
24 {
25     typedef Container M;
26     typedef std::pair<typename M::iterator, bool> R;
27     typedef typename M::value_type VT;
28     M m;
29 
30     const VT v1(2, 2.5);
31     R r = m.insert(v1);
32     assert(r.second);
33     assert(r.first == m.begin());
34     assert(m.size() == 1);
35     assert(r.first->first == 2);
36     assert(r.first->second == 2.5);
37 
38     const VT v2(1, 1.5);
39     r = m.insert(v2);
40     assert(r.second);
41     assert(r.first == m.begin());
42     assert(m.size() == 2);
43     assert(r.first->first == 1);
44     assert(r.first->second == 1.5);
45 
46     const VT v3(3, 3.5);
47     r = m.insert(v3);
48     assert(r.second);
49     assert(r.first == prev(m.end()));
50     assert(m.size() == 3);
51     assert(r.first->first == 3);
52     assert(r.first->second == 3.5);
53 
54     const VT v4(3, 4.5);
55     r = m.insert(v4);
56     assert(!r.second);
57     assert(r.first == prev(m.end()));
58     assert(m.size() == 3);
59     assert(r.first->first == 3);
60     assert(r.first->second == 3.5);
61 }
62 
main()63 int main()
64 {
65     do_insert_cv_test<std::map<int, double> >();
66 #if TEST_STD_VER >= 11
67     {
68         typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
69         do_insert_cv_test<M>();
70     }
71 #endif
72 }
73