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

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