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 // <set>
10
11 // class multiset
12
13 // template <class InputIterator>
14 // multiset(InputIterator first, InputIterator last,
15 // const value_compare& comp, const allocator_type& a);
16
17 #include <set>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "test_iterators.h"
22 #include "../../../test_compare.h"
23 #include "test_allocator.h"
24
main(int,char **)25 int main(int, char**)
26 {
27 {
28 typedef int V;
29 V ar[] =
30 {
31 1,
32 1,
33 1,
34 2,
35 2,
36 2,
37 3,
38 3,
39 3
40 };
41 typedef test_less<V> C;
42 typedef test_allocator<V> A;
43 std::multiset<V, C, A> m(cpp17_input_iterator<const V*>(ar),
44 cpp17_input_iterator<const V*>(ar+sizeof(ar)/sizeof(ar[0])),
45 C(5), A(7));
46 assert(m.value_comp() == C(5));
47 assert(m.get_allocator() == A(7));
48 assert(m.size() == 9);
49 assert(std::distance(m.begin(), m.end()) == 9);
50 assert(*std::next(m.begin(), 0) == 1);
51 assert(*std::next(m.begin(), 1) == 1);
52 assert(*std::next(m.begin(), 2) == 1);
53 assert(*std::next(m.begin(), 3) == 2);
54 assert(*std::next(m.begin(), 4) == 2);
55 assert(*std::next(m.begin(), 5) == 2);
56 assert(*std::next(m.begin(), 6) == 3);
57 assert(*std::next(m.begin(), 7) == 3);
58 assert(*std::next(m.begin(), 8) == 3);
59 }
60 #if TEST_STD_VER > 11
61 {
62 typedef int V;
63 V ar[] =
64 {
65 1,
66 1,
67 1,
68 2,
69 2,
70 2,
71 3,
72 3,
73 3
74 };
75 typedef test_allocator<V> A;
76 typedef test_less<int> C;
77 A a;
78 std::multiset<V, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a);
79
80 assert(m.size() == 9);
81 assert(std::distance(m.begin(), m.end()) == 9);
82 assert(*std::next(m.begin(), 0) == 1);
83 assert(*std::next(m.begin(), 1) == 1);
84 assert(*std::next(m.begin(), 2) == 1);
85 assert(*std::next(m.begin(), 3) == 2);
86 assert(*std::next(m.begin(), 4) == 2);
87 assert(*std::next(m.begin(), 5) == 2);
88 assert(*std::next(m.begin(), 6) == 3);
89 assert(*std::next(m.begin(), 7) == 3);
90 assert(*std::next(m.begin(), 8) == 3);
91 assert(m.get_allocator() == a);
92 }
93 #endif
94
95 return 0;
96 }
97