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 {
32 typedef int V;
33 V ar[] =
34 {
35 1,
36 1,
37 1,
38 2,
39 2,
40 2,
41 3,
42 3,
43 3
44 };
45 typedef test_less<V> C;
46 typedef test_allocator<V> A;
47 std::set<V, C, A> m(cpp17_input_iterator<const V*>(ar),
48 cpp17_input_iterator<const V*>(ar+sizeof(ar)/sizeof(ar[0])),
49 C(5), A(7));
50 assert(m.value_comp() == C(5));
51 assert(m.get_allocator() == A(7));
52 assert(m.size() == 3);
53 assert(std::distance(m.begin(), m.end()) == 3);
54 assert(*m.begin() == 1);
55 assert(*std::next(m.begin()) == 2);
56 assert(*std::next(m.begin(), 2) == 3);
57 }
58#if TEST_STD_VER > 11
59 {
60 typedef int V;
61 V ar[] =
62 {
63 1,
64 1,
65 1,
66 2,
67 2,
68 2,
69 3,
70 3,
71 3
72 };
73 typedef test_allocator<V> A;
74 typedef test_less<int> C;
75 A a(7);
76 std::set<V, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a);
77
78 assert(m.size() == 3);
79 assert(std::distance(m.begin(), m.end()) == 3);
80 assert(*m.begin() == 1);
81 assert(*std::next(m.begin()) == 2);
82 assert(*std::next(m.begin(), 2) == 3);
83 assert(m.get_allocator() == a);
84 }
85#endif
86
87 return 0;
88}
89

source code of libcxx/test/std/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp