llvm-project
88 строк · 2.0 Кб
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 set
12
13// template <class InputIterator>
14// set(InputIterator first, InputIterator last,
15// const value_compare& comp, const allocator_type& a);
16//
17// template <class InputIterator>
18// set(InputIterator first, InputIterator last,
19// const allocator_type& a);
20
21#include <set>
22#include <cassert>
23
24#include "test_macros.h"
25#include "test_iterators.h"
26#include "../../../test_compare.h"
27#include "test_allocator.h"
28
29int main(int, char**)
30{
31{
32typedef int V;
33V ar[] =
34{
351,
361,
371,
382,
392,
402,
413,
423,
433
44};
45typedef test_less<V> C;
46typedef test_allocator<V> A;
47std::set<V, C, A> m(cpp17_input_iterator<const V*>(ar),
48cpp17_input_iterator<const V*>(ar+sizeof(ar)/sizeof(ar[0])),
49C(5), A(7));
50assert(m.value_comp() == C(5));
51assert(m.get_allocator() == A(7));
52assert(m.size() == 3);
53assert(std::distance(m.begin(), m.end()) == 3);
54assert(*m.begin() == 1);
55assert(*std::next(m.begin()) == 2);
56assert(*std::next(m.begin(), 2) == 3);
57}
58#if TEST_STD_VER > 11
59{
60typedef int V;
61V ar[] =
62{
631,
641,
651,
662,
672,
682,
693,
703,
713
72};
73typedef test_allocator<V> A;
74typedef test_less<int> C;
75A a(7);
76std::set<V, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a);
77
78assert(m.size() == 3);
79assert(std::distance(m.begin(), m.end()) == 3);
80assert(*m.begin() == 1);
81assert(*std::next(m.begin()) == 2);
82assert(*std::next(m.begin(), 2) == 3);
83assert(m.get_allocator() == a);
84}
85#endif
86
87return 0;
88}
89