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// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10
11// <flat_set>
12
13// explicit flat_set(const key_compare& comp);
14// template <class Alloc>
15// flat_set(const key_compare& comp, const Alloc& a);
16
17#include <deque>
18#include <flat_set>
19#include <functional>
20#include <type_traits>
21#include <vector>
22
23#include "test_macros.h"
24#include "../../../test_compare.h"
25#include "test_allocator.h"
26
27void test() {
28 {
29 // The constructors in this subclause shall not participate in overload
30 // resolution unless uses_allocator_v<container_type, Alloc> is true.
31
32 using C = test_less<int>;
33 using A1 = test_allocator<int>;
34 using A2 = other_allocator<int>;
35 using V1 = std::vector<int, A1>;
36 using V2 = std::vector<int, A2>;
37 using M1 = std::flat_set<int, C, V1>;
38 using M2 = std::flat_set<int, C, V2>;
39 static_assert(std::is_constructible_v<M1, const C&, const A1&>);
40 static_assert(std::is_constructible_v<M2, const C&, const A2&>);
41 static_assert(!std::is_constructible_v<M1, const C&, const A2&>);
42 static_assert(!std::is_constructible_v<M2, const C&, const A1&>);
43 }
44 {
45 using C = test_less<int>;
46 auto m = std::flat_set<int, C>(C(3));
47 assert(m.empty());
48 assert(m.begin() == m.end());
49 assert(m.key_comp() == C(3));
50 }
51 {
52 // The one-argument ctor is explicit.
53 using C = test_less<int>;
54 static_assert(std::is_constructible_v<std::flat_set<int, C>, C>);
55 static_assert(!std::is_convertible_v<C, std::flat_set<int, C>>);
56
57 static_assert(std::is_constructible_v<std::flat_set<int>, std::less<int>>);
58 static_assert(!std::is_convertible_v<std::less<int>, std::flat_set<int>>);
59 }
60 {
61 using C = test_less<int>;
62 using A1 = test_allocator<int>;
63 auto m = std::flat_set<int, C, std::vector<int, A1>>(C(4), A1(5));
64 assert(m.empty());
65 assert(m.begin() == m.end());
66 assert(m.key_comp() == C(4));
67 auto keys = std::move(m).extract();
68 assert(keys.get_allocator() == A1(5));
69 }
70 {
71 // explicit(false)
72 using C = test_less<int>;
73 using A1 = test_allocator<int>;
74 std::flat_set<int, C, std::deque<int, A1>> m = {C(4), A1(5)};
75 assert(m.empty());
76 assert(m.begin() == m.end());
77 assert(m.key_comp() == C(4));
78 auto keys = std::move(m).extract();
79 assert(keys.get_allocator() == A1(5));
80 }
81}
82
83int main(int, char**) {
84 test();
85
86 return 0;
87}
88

source code of libcxx/test/std/containers/container.adaptors/flat.set/flat.set.cons/compare.pass.cpp