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// noexcept(
15// is_nothrow_default_constructible_v<key_container_type> &&
16// is_nothrow_default_constructible_v<mapped_container_type> &&
17// is_nothrow_default_constructible_v<key_compare>);
18
19// This tests a conforming extension
20
21#include <cassert>
22#include <flat_map>
23#include <functional>
24#include <vector>
25
26#include "test_macros.h"
27#include "MoveOnly.h"
28#include "test_allocator.h"
29
30struct ThrowingCtorComp {
31 ThrowingCtorComp() noexcept(false) {}
32 bool operator()(const auto&, const auto&) const { return false; }
33};
34
35int main(int, char**) {
36#if defined(_LIBCPP_VERSION)
37 {
38 using C = std::flat_map<MoveOnly, MoveOnly>;
39 static_assert(std::is_nothrow_default_constructible_v<C>);
40 C c;
41 }
42 {
43 using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, test_allocator<MoveOnly>>>;
44 static_assert(std::is_nothrow_default_constructible_v<C>);
45 C c;
46 }
47#endif // _LIBCPP_VERSION
48 {
49 using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, other_allocator<MoveOnly>>>;
50 static_assert(!std::is_nothrow_default_constructible_v<C>);
51 C c;
52 }
53 {
54 using C = std::flat_map<MoveOnly, MoveOnly, ThrowingCtorComp>;
55 static_assert(!std::is_nothrow_default_constructible_v<C>);
56 C c;
57 }
58 return 0;
59}
60

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