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();
14
15#include <cassert>
16#include <deque>
17#include <flat_map>
18#include <functional>
19#include <type_traits>
20#include <vector>
21
22#include "test_macros.h"
23#include "min_allocator.h"
24#include "test_allocator.h"
25
26struct DefaultCtableComp {
27 explicit DefaultCtableComp() { default_constructed_ = true; }
28 bool operator()(int, int) const { return false; }
29 bool default_constructed_ = false;
30};
31
32int main(int, char**) {
33 {
34 std::flat_map<int, char*> m;
35 assert(m.empty());
36 }
37 {
38 // explicit(false)
39 std::flat_map<int, char*> m = {};
40 assert(m.empty());
41 }
42 {
43 std::flat_map<int, char*, DefaultCtableComp, std::deque<int, min_allocator<int>>> m;
44 assert(m.empty());
45 assert(m.begin() == m.end());
46 assert(m.key_comp().default_constructed_);
47 }
48 {
49 using A1 = explicit_allocator<int>;
50 using A2 = explicit_allocator<char*>;
51 {
52 std::flat_map<int, char*, DefaultCtableComp, std::vector<int, A1>, std::vector<char*, A2>> m;
53 assert(m.empty());
54 assert(m.key_comp().default_constructed_);
55 }
56 {
57 A1 a1;
58 std::flat_map<int, int, DefaultCtableComp, std::vector<int, A1>, std::vector<int, A1>> m(a1);
59 assert(m.empty());
60 assert(m.key_comp().default_constructed_);
61 }
62 }
63 {
64 // If an allocator is given, it must be usable by both containers.
65 using A = test_allocator<int>;
66 using M = std::flat_map<int, int, std::less<>, std::vector<int>, std::vector<int, A>>;
67 static_assert(std::is_constructible_v<M>);
68 static_assert(!std::is_constructible_v<M, std::allocator<int>>);
69 static_assert(!std::is_constructible_v<M, A>);
70 }
71 return 0;
72}
73

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