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

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