| 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_multimap& operator=(unordered_multimap&& 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 | |
| 27 | template <class T> |
| 28 | struct 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 | |
| 37 | template <class T> |
| 38 | struct 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 | |
| 44 | template <class T> |
| 45 | struct always_equal_alloc { |
| 46 | using value_type = T; |
| 47 | always_equal_alloc(const always_equal_alloc&); |
| 48 | void allocate(std::size_t); |
| 49 | }; |
| 50 | |
| 51 | template <class T> |
| 52 | struct 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 | |
| 59 | template <template <class> class Alloc> |
| 60 | using unordered_set_alloc = |
| 61 | std::unordered_multimap<MoveOnly, |
| 62 | MoveOnly, |
| 63 | std::hash<MoveOnly>, |
| 64 | std::equal_to<MoveOnly>, |
| 65 | Alloc<std::pair<const MoveOnly, MoveOnly>>>; |
| 66 | |
| 67 | static_assert(std::is_nothrow_move_assignable<unordered_set_alloc<std::allocator>>::value, "" ); |
| 68 | static_assert(!std::is_nothrow_move_assignable<unordered_set_alloc<test_allocator>>::value, "" ); |
| 69 | #if TEST_STD_VER >= 17 |
| 70 | static_assert(std::is_nothrow_move_assignable<unordered_set_alloc<always_equal_alloc>>::value, "" ); |
| 71 | #endif |
| 72 | static_assert(!std::is_nothrow_move_assignable<unordered_set_alloc<not_always_equal_alloc>>::value, "" ); |
| 73 | #if defined(_LIBCPP_VERSION) |
| 74 | static_assert(std::is_nothrow_move_assignable<unordered_set_alloc<other_allocator>>::value, "" ); |
| 75 | #endif // _LIBCPP_VERSION |
| 76 | static_assert(!std::is_nothrow_move_assignable<std::unordered_map<int, int, some_hash<int>>>::value, "" ); |
| 77 | static_assert(!std::is_nothrow_move_assignable<std::unordered_map<int, int, std::hash<int>, some_comp<int>>>::value, |
| 78 | "" ); |
| 79 | |