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 // template <class InputIterator>
15 //     multimap(InputIterator first, InputIterator last);
16 
17 #include <map>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 
main()23 int main()
24 {
25     {
26     typedef std::pair<const int, double> V;
27     V ar[] =
28     {
29         V(1, 1),
30         V(1, 1.5),
31         V(1, 2),
32         V(2, 1),
33         V(2, 1.5),
34         V(2, 2),
35         V(3, 1),
36         V(3, 1.5),
37         V(3, 2),
38     };
39     std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
40     assert(m.size() == 9);
41     assert(distance(m.begin(), m.end()) == 9);
42     assert(*m.begin() == V(1, 1));
43     assert(*next(m.begin()) == V(1, 1.5));
44     assert(*next(m.begin(), 2) == V(1, 2));
45     assert(*next(m.begin(), 3) == V(2, 1));
46     assert(*next(m.begin(), 4) == V(2, 1.5));
47     assert(*next(m.begin(), 5) == V(2, 2));
48     assert(*next(m.begin(), 6) == V(3, 1));
49     assert(*next(m.begin(), 7) == V(3, 1.5));
50     assert(*next(m.begin(), 8) == V(3, 2));
51     }
52 #if TEST_STD_VER >= 11
53     {
54     typedef std::pair<const int, double> V;
55     V ar[] =
56     {
57         V(1, 1),
58         V(1, 1.5),
59         V(1, 2),
60         V(2, 1),
61         V(2, 1.5),
62         V(2, 2),
63         V(3, 1),
64         V(3, 1.5),
65         V(3, 2),
66     };
67     std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
68     assert(m.size() == 9);
69     assert(distance(m.begin(), m.end()) == 9);
70     assert(*m.begin() == V(1, 1));
71     assert(*next(m.begin()) == V(1, 1.5));
72     assert(*next(m.begin(), 2) == V(1, 2));
73     assert(*next(m.begin(), 3) == V(2, 1));
74     assert(*next(m.begin(), 4) == V(2, 1.5));
75     assert(*next(m.begin(), 5) == V(2, 2));
76     assert(*next(m.begin(), 6) == V(3, 1));
77     assert(*next(m.begin(), 7) == V(3, 1.5));
78     assert(*next(m.begin(), 8) == V(3, 2));
79     }
80 #if TEST_STD_VER > 11
81     {
82     typedef std::pair<const int, double> V;
83     V ar[] =
84     {
85         V(1, 1),
86         V(1, 1.5),
87         V(1, 2),
88         V(2, 1),
89         V(2, 1.5),
90         V(2, 2),
91         V(3, 1),
92         V(3, 1.5),
93         V(3, 2),
94     };
95     typedef min_allocator<std::pair<const int, double>> A;
96     A a;
97     std::multimap<int, double, std::less<int>, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a);
98     assert(m.size() == 9);
99     assert(distance(m.begin(), m.end()) == 9);
100     assert(*m.begin() == V(1, 1));
101     assert(*next(m.begin()) == V(1, 1.5));
102     assert(*next(m.begin(), 2) == V(1, 2));
103     assert(*next(m.begin(), 3) == V(2, 1));
104     assert(*next(m.begin(), 4) == V(2, 1.5));
105     assert(*next(m.begin(), 5) == V(2, 2));
106     assert(*next(m.begin(), 6) == V(3, 1));
107     assert(*next(m.begin(), 7) == V(3, 1.5));
108     assert(*next(m.begin(), 8) == V(3, 2));
109     assert(m.get_allocator() == a);
110     }
111 #endif
112 #endif
113 }
114