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 multimap
13 
14 // iterator 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_test()23 void do_insert_test() {
24     typedef Container M;
25     typedef typename M::iterator R;
26     typedef typename M::value_type VT;
27     M m;
28     const VT v1(2, 2.5);
29     R r = m.insert(v1);
30     assert(r == m.begin());
31     assert(m.size() == 1);
32     assert(r->first == 2);
33     assert(r->second == 2.5);
34 
35     const VT v2(1, 1.5);
36     r = m.insert(v2);
37     assert(r == m.begin());
38     assert(m.size() == 2);
39     assert(r->first == 1);
40     assert(r->second == 1.5);
41 
42     const VT v3(3, 3.5);
43     r = m.insert(v3);
44     assert(r == prev(m.end()));
45     assert(m.size() == 3);
46     assert(r->first == 3);
47     assert(r->second == 3.5);
48 
49     const VT v4(3, 3.5);
50     r = m.insert(v4);
51     assert(r == prev(m.end()));
52     assert(m.size() == 4);
53     assert(r->first == 3);
54     assert(r->second == 3.5);
55 }
56 
main()57 int main()
58 {
59     {
60         typedef std::multimap<int, double> Container;
61         do_insert_test<Container>();
62     }
63 #if TEST_STD_VER >= 11
64     {
65         typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> Container;
66         do_insert_test<Container>();
67     }
68 #endif
69 }
70