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_multiset(const flat_multiset& 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, 3, 1}, test_allocator<int>(6));
28 const int expected[] = {1, 1, 3, 3, 5};
29 using M = std::flat_multiset<int, C, decltype(ks)>;
30 auto mo = M(ks, C(5));
31 auto m = mo;
32
33 assert(m.key_comp() == C(5));
34 assert(std::ranges::equal(m, expected));
35 auto keys = std::move(m).extract();
36 assert(keys.get_allocator() == test_allocator<int>(6));
37
38 // mo is unchanged
39 assert(mo.key_comp() == C(5));
40 assert(std::ranges::equal(mo, expected));
41 auto keys2 = std::move(mo).extract();
42 assert(keys2.get_allocator() == test_allocator<int>(6));
43 }
44 {
45 using C = test_less<int>;
46 using Ks = std::vector<int, other_allocator<int>>;
47 auto ks = Ks({1, 3, 5, 3, 1}, other_allocator<int>(6));
48 const int expected[] = {1, 1, 3, 3, 5};
49 using M = std::flat_multiset<int, C, Ks>;
50 auto mo = M(Ks(ks, other_allocator<int>(6)), C(5));
51 auto m = mo;
52
53 assert(m.key_comp() == C(5));
54 assert(std::ranges::equal(m, expected));
55 auto keys = std::move(m).extract();
56 assert(keys.get_allocator() == other_allocator<int>(-2));
57
58 // mo is unchanged
59 assert(mo.key_comp() == C(5));
60 assert(std::ranges::equal(mo, expected));
61 auto keys2 = std::move(mo).extract();
62 assert(keys2.get_allocator() == other_allocator<int>(6));
63 }
64}
65
66int main(int, char**) {
67 test();
68
69 return 0;
70}
71

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