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

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