llvm-project
96 строк · 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// <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
25int main(int, char**)
26{
27{
28typedef int V;
29V ar[] =
30{
311,
321,
331,
342,
352,
362,
373,
383,
393
40};
41typedef test_less<V> C;
42typedef test_allocator<V> A;
43std::multiset<V, C, A> m(cpp17_input_iterator<const V*>(ar),
44cpp17_input_iterator<const V*>(ar+sizeof(ar)/sizeof(ar[0])),
45C(5), A(7));
46assert(m.value_comp() == C(5));
47assert(m.get_allocator() == A(7));
48assert(m.size() == 9);
49assert(std::distance(m.begin(), m.end()) == 9);
50assert(*std::next(m.begin(), 0) == 1);
51assert(*std::next(m.begin(), 1) == 1);
52assert(*std::next(m.begin(), 2) == 1);
53assert(*std::next(m.begin(), 3) == 2);
54assert(*std::next(m.begin(), 4) == 2);
55assert(*std::next(m.begin(), 5) == 2);
56assert(*std::next(m.begin(), 6) == 3);
57assert(*std::next(m.begin(), 7) == 3);
58assert(*std::next(m.begin(), 8) == 3);
59}
60#if TEST_STD_VER > 11
61{
62typedef int V;
63V ar[] =
64{
651,
661,
671,
682,
692,
702,
713,
723,
733
74};
75typedef test_allocator<V> A;
76typedef test_less<int> C;
77A a;
78std::multiset<V, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a);
79
80assert(m.size() == 9);
81assert(std::distance(m.begin(), m.end()) == 9);
82assert(*std::next(m.begin(), 0) == 1);
83assert(*std::next(m.begin(), 1) == 1);
84assert(*std::next(m.begin(), 2) == 1);
85assert(*std::next(m.begin(), 3) == 2);
86assert(*std::next(m.begin(), 4) == 2);
87assert(*std::next(m.begin(), 5) == 2);
88assert(*std::next(m.begin(), 6) == 3);
89assert(*std::next(m.begin(), 7) == 3);
90assert(*std::next(m.begin(), 8) == 3);
91assert(m.get_allocator() == a);
92}
93#endif
94
95return 0;
96}
97