llvm-project
75 строк · 1.9 Кб
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// template <class InputIterator>
14// map(InputIterator first, InputIterator last, const key_compare& comp);
15
16#include <map>
17#include <cassert>
18
19#include "test_macros.h"
20#include "../../../test_compare.h"
21#include "min_allocator.h"
22
23int main(int, char**)
24{
25{
26typedef std::pair<const int, double> V;
27V ar[] =
28{
29V(1, 1),
30V(1, 1.5),
31V(1, 2),
32V(2, 1),
33V(2, 1.5),
34V(2, 2),
35V(3, 1),
36V(3, 1.5),
37V(3, 2),
38};
39typedef test_less<int> C;
40std::map<int, double, C> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5));
41assert(m.key_comp() == C(5));
42assert(m.size() == 3);
43assert(std::distance(m.begin(), m.end()) == 3);
44assert(*m.begin() == V(1, 1));
45assert(*std::next(m.begin()) == V(2, 1));
46assert(*std::next(m.begin(), 2) == V(3, 1));
47}
48#if TEST_STD_VER >= 11
49{
50typedef std::pair<const int, double> V;
51V ar[] =
52{
53V(1, 1),
54V(1, 1.5),
55V(1, 2),
56V(2, 1),
57V(2, 1.5),
58V(2, 2),
59V(3, 1),
60V(3, 1.5),
61V(3, 2),
62};
63typedef test_less<int> C;
64std::map<int, double, C, min_allocator<std::pair<const int, double>>> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5));
65assert(m.key_comp() == C(5));
66assert(m.size() == 3);
67assert(std::distance(m.begin(), m.end()) == 3);
68assert(*m.begin() == V(1, 1));
69assert(*std::next(m.begin()) == V(2, 1));
70assert(*std::next(m.begin(), 2) == V(3, 1));
71}
72#endif
73
74return 0;
75}
76