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// flat_set(const flat_set&, const allocator_type&);
14
15#include <algorithm>
16#include <cassert>
17#include <deque>
18#include <flat_set>
19#include <functional>
20#include <vector>
21
22#include "test_macros.h"
23#include "../../../test_compare.h"
24#include "test_allocator.h"
25
26void test() {
27 {
28 // The constructors in this subclause shall not participate in overload
29 // resolution unless uses_allocator_v<container_type, Alloc> is true.
30
31 using C = test_less<int>;
32 using A1 = test_allocator<int>;
33 using A2 = other_allocator<int>;
34 using V1 = std::vector<int, A1>;
35 using V2 = std::vector<int, A2>;
36 using M1 = std::flat_set<int, C, V1>;
37 using M2 = std::flat_set<int, C, V2>;
38 static_assert(std::is_constructible_v<M1, const M1&, const A1&>);
39 static_assert(std::is_constructible_v<M2, const M2&, const A2&>);
40 static_assert(!std::is_constructible_v<M1, const M1&, const A2&>);
41 static_assert(!std::is_constructible_v<M2, const M2&, const A1&>);
42 }
43 {
44 using C = test_less<int>;
45 std::vector<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
46 using M = std::flat_set<int, C, decltype(ks)>;
47 auto mo = M(ks, C(5));
48 auto m = M(mo, test_allocator<int>(3));
49
50 assert(m.key_comp() == C(5));
51 assert(std::ranges::equal(m, ks));
52 auto keys = std::move(m).extract();
53 assert(keys.get_allocator() == test_allocator<int>(3));
54
55 // mo is unchanged
56 assert(mo.key_comp() == C(5));
57 assert(std::ranges::equal(mo, ks));
58 auto keys2 = std::move(mo).extract();
59 assert(keys2.get_allocator() == test_allocator<int>(6));
60 }
61}
62
63int main(int, char**) {
64 test();
65
66 return 0;
67}
68

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