Debian Codegraph @

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

raw
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
29 template <class T>
30 struct some_comp {
31 typedef T value_type;
32 some_comp();
33 some_comp(const some_comp&);
34 bool operator()(const T&, const T&) const { return false; }
35 };
36
37 template <class T>
38 struct some_hash {
39 typedef T value_type;
40 some_hash();
41 some_hash(const some_hash&);
42
43 std::size_t operator()(T const&) const;
44 };
45
46 int main(int, char**) {
47 #if defined(_LIBCPP_VERSION)
48 {
49 typedef std::unordered_map<MoveOnly, MoveOnly> C;
50 static_assert(std::is_nothrow_default_constructible<C>::value, "");
51 }
52 {
53 typedef std::unordered_map<MoveOnly,
54 MoveOnly,
55 std::hash<MoveOnly>,
56 std::equal_to<MoveOnly>,
57 test_allocator<std::pair<const MoveOnly, MoveOnly>>>
58 C;
59 static_assert(std::is_nothrow_default_constructible<C>::value, "");
60 }
61 #endif // _LIBCPP_VERSION
62 {
63 typedef std::unordered_map<MoveOnly,
64 MoveOnly,
65 std::hash<MoveOnly>,
66 std::equal_to<MoveOnly>,
67 other_allocator<std::pair<const MoveOnly, MoveOnly>>>
68 C;
69 static_assert(!std::is_nothrow_default_constructible<C>::value, "");
70 }
71 {
72 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
73 static_assert(!std::is_nothrow_default_constructible<C>::value, "");
74 }
75 {
76 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>, some_comp<MoveOnly>> C;
77 static_assert(!std::is_nothrow_default_constructible<C>::value, "");
78 }
79
80 return 0;
81 }