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_set>
10
11// unordered_multiset& operator=(unordered_multiset&& 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_set>
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_multiset<MoveOnly, std::hash<MoveOnly>, std::equal_to<MoveOnly>, Alloc<MoveOnly>>;
62
63static_assert(std::is_nothrow_move_assignable<unordered_set_alloc<std::allocator>>::value, "");
64static_assert(!std::is_nothrow_move_assignable<unordered_set_alloc<test_allocator>>::value, "");
65#if TEST_STD_VER > 17
66static_assert(std::is_nothrow_move_assignable<unordered_set_alloc<always_equal_alloc>>::value, "");
67#endif
68static_assert(!std::is_nothrow_move_assignable<unordered_set_alloc<not_always_equal_alloc>>::value, "");
69#if defined(_LIBCPP_VERSION)
70static_assert(std::is_nothrow_move_assignable<unordered_set_alloc<other_allocator>>::value, "");
71#endif // _LIBCPP_VERSION
72static_assert(!std::is_nothrow_move_assignable<std::unordered_multiset<int, some_hash<int>>>::value, "");
73static_assert(!std::is_nothrow_move_assignable<std::unordered_multiset<int, std::hash<int>, some_comp<int>>>::value,
74 "");
75

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