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& m);
14
15#include <algorithm>
16#include <cassert>
17#include <flat_set>
18#include <vector>
19
20#include "test_macros.h"
21#include "../../../test_compare.h"
22#include "test_allocator.h"
23
24void test() {
25 {
26 using C = test_less<int>;
27 std::vector<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
28 using M = std::flat_set<int, C, decltype(ks)>;
29 auto mo = M(ks, C(5));
30 auto m = mo;
31
32 assert(m.key_comp() == C(5));
33 assert(std::ranges::equal(m, ks));
34 auto keys = std::move(m).extract();
35 assert(keys.get_allocator() == test_allocator<int>(6));
36
37 // mo is unchanged
38 assert(mo.key_comp() == C(5));
39 assert(std::ranges::equal(mo, ks));
40 auto keys2 = std::move(mo).extract();
41 assert(keys2.get_allocator() == test_allocator<int>(6));
42 }
43 {
44 using C = test_less<int>;
45 using Ks = std::vector<int, other_allocator<int>>;
46 auto ks = Ks({1, 3, 5}, other_allocator<int>(6));
47 using M = std::flat_set<int, C, Ks>;
48 auto mo = M(Ks(ks, other_allocator<int>(6)), C(5));
49 auto m = mo;
50
51 assert(m.key_comp() == C(5));
52 assert(std::ranges::equal(m, ks));
53 auto keys = std::move(m).extract();
54 assert(keys.get_allocator() == other_allocator<int>(-2));
55
56 // mo is unchanged
57 assert(mo.key_comp() == C(5));
58 assert(std::ranges::equal(mo, ks));
59 auto keys2 = std::move(mo).extract();
60 assert(keys2.get_allocator() == other_allocator<int>(6));
61 }
62}
63
64int main(int, char**) {
65 test();
66
67 return 0;
68}
69

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