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

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