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

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