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// <unordered_map>
10
11// unordered_map()
12// noexcept(
13// is_nothrow_default_constructible<allocator_type>::value &&
14// is_nothrow_default_constructible<key_compare>::value &&
15// is_nothrow_copy_constructible<key_compare>::value);
16
17// This tests a conforming extension
18
19// UNSUPPORTED: c++03
20
21#include <unordered_map>
22#include <cassert>
23
24#include "test_macros.h"
25#include "MoveOnly.h"
26#include "test_allocator.h"
27#include "../../../test_hash.h"
28
29template <class T>
30struct some_comp
31{
32 typedef T value_type;
33 some_comp();
34 some_comp(const some_comp&);
35 bool operator()(const T&, const T&) const { return false; }
36};
37
38template <class T>
39struct some_hash
40{
41 typedef T value_type;
42 some_hash();
43 some_hash(const some_hash&);
44
45 std::size_t operator()(T const&) const;
46};
47
48int main(int, char**)
49{
50#if defined(_LIBCPP_VERSION)
51 {
52 typedef std::unordered_map<MoveOnly, MoveOnly> C;
53 static_assert(std::is_nothrow_default_constructible<C>::value, "");
54 }
55 {
56 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
57 std::equal_to<MoveOnly>, test_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
58 static_assert(std::is_nothrow_default_constructible<C>::value, "");
59 }
60#endif // _LIBCPP_VERSION
61 {
62 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
63 std::equal_to<MoveOnly>, other_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
64 static_assert(!std::is_nothrow_default_constructible<C>::value, "");
65 }
66 {
67 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
68 static_assert(!std::is_nothrow_default_constructible<C>::value, "");
69 }
70 {
71 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
72 some_comp<MoveOnly>> C;
73 static_assert(!std::is_nothrow_default_constructible<C>::value, "");
74 }
75
76 return 0;
77}
78

source code of libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default_noexcept.pass.cpp