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// UNSUPPORTED: c++03
10
11// <map>
12
13// class map
14
15// map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
16
17#include <map>
18#include <cassert>
19#include "test_macros.h"
20#include "../../../test_compare.h"
21#include "test_allocator.h"
22#include "min_allocator.h"
23
24int main(int, char**) {
25 {
26 typedef std::pair<const int, double> V;
27 typedef test_less<int> C;
28 typedef test_allocator<std::pair<const int, double> > A;
29 std::map<int, double, C, A> m(
30 {{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}}, C(3), A(6));
31 assert(m.size() == 3);
32 assert(std::distance(m.begin(), m.end()) == 3);
33 assert(*m.begin() == V(1, 1));
34 assert(*std::next(m.begin()) == V(2, 1));
35 assert(*std::next(m.begin(), 2) == V(3, 1));
36 assert(m.key_comp() == C(3));
37 assert(m.get_allocator() == A(6));
38 }
39 {
40 typedef std::pair<const int, double> V;
41 typedef test_less<int> C;
42 typedef min_allocator<std::pair<const int, double> > A;
43 std::map<int, double, C, A> m(
44 {{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}}, C(3), A());
45 assert(m.size() == 3);
46 assert(std::distance(m.begin(), m.end()) == 3);
47 assert(*m.begin() == V(1, 1));
48 assert(*std::next(m.begin()) == V(2, 1));
49 assert(*std::next(m.begin(), 2) == V(3, 1));
50 assert(m.key_comp() == C(3));
51 assert(m.get_allocator() == A());
52 }
53 {
54 typedef std::pair<const int, double> V;
55 typedef min_allocator<V> A;
56 typedef test_less<int> C;
57 typedef std::map<int, double, C, A> M;
58 A a;
59 M m({{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}}, a);
60
61 assert(m.size() == 3);
62 assert(std::distance(m.begin(), m.end()) == 3);
63 assert(*m.begin() == V(1, 1));
64 assert(*std::next(m.begin()) == V(2, 1));
65 assert(*std::next(m.begin(), 2) == V(3, 1));
66 assert(m.get_allocator() == a);
67 }
68 {
69 typedef std::pair<const int, double> V;
70 typedef explicit_allocator<V> A;
71 typedef test_less<int> C;
72 A a;
73 std::map<int, double, C, A> m(
74 {{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}}, C(3), a);
75 assert(m.size() == 3);
76 assert(std::distance(m.begin(), m.end()) == 3);
77 assert(*m.begin() == V(1, 1));
78 assert(*std::next(m.begin()) == V(2, 1));
79 assert(*std::next(m.begin(), 2) == V(3, 1));
80 assert(m.key_comp() == C(3));
81 assert(m.get_allocator() == a);
82 }
83
84 return 0;
85}
86

source code of libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp