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

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