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// template<class Allocator>
14// explicit flat_map(const Allocator& a);
15
16#include <cassert>
17#include <flat_map>
18#include <functional>
19#include <vector>
20
21#include "test_macros.h"
22#include "test_allocator.h"
23#include "../../../test_compare.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_map<int, int, C, V1, V1>;
37 using M2 = std::flat_map<int, int, C, V1, V2>;
38 using M3 = std::flat_map<int, int, C, V2, V1>;
39 static_assert(std::is_constructible_v<M1, const A1&>);
40 static_assert(!std::is_constructible_v<M1, const A2&>);
41 static_assert(!std::is_constructible_v<M2, const A2&>);
42 static_assert(!std::is_constructible_v<M3, const A2&>);
43 }
44 {
45 // explicit
46 using M =
47 std::flat_map<int,
48 long,
49 std::less<int>,
50 std::vector<int, test_allocator<int>>,
51 std::vector<long, test_allocator<long>>>;
52
53 static_assert(std::is_constructible_v<M, test_allocator<int>>);
54 static_assert(!std::is_convertible_v<test_allocator<int>, M>);
55 }
56 {
57 using A = test_allocator<short>;
58 using M =
59 std::flat_map<int,
60 long,
61 std::less<int>,
62 std::vector<int, test_allocator<int>>,
63 std::vector<long, test_allocator<long>>>;
64 M m(A(0, 5));
65 assert(m.empty());
66 assert(m.begin() == m.end());
67 assert(m.keys().get_allocator().get_id() == 5);
68 assert(m.values().get_allocator().get_id() == 5);
69 }
70
71 return 0;
72}
73

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