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