1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03
14 // void swap(unordered_map& c)
16 // (!allocator_type::propagate_on_container_swap::value ||
17 // __is_nothrow_swappable<allocator_type>::value) &&
18 // __is_nothrow_swappable<hasher>::value &&
19 // __is_nothrow_swappable<key_equal>::value);
21 // In C++17, the standard says that swap shall have:
22 // noexcept(allocator_traits<Allocator>::is_always_equal::value &&
23 // noexcept(swap(declval<Hash&>(), declval<Hash&>())) &&
24 // noexcept(swap(declval<Pred&>(), declval<Pred&>())));
26 // This tests a conforming extension
28 #include <unordered_map>
32 #include "test_macros.h"
34 #include "test_allocator.h"
42 some_comp(const some_comp&) {}
43 bool operator()(const T&, const T&) const { return false; }
52 some_comp2(const some_comp2&) {}
53 bool operator()(const T&, const T&) const { return false; }
56 #if TEST_STD_VER >= 14
58 void swap(some_comp2<T>&, some_comp2<T>&) noexcept {}
66 some_hash(const some_hash&);
67 std::size_t operator()(T const&) const;
75 some_hash2(const some_hash2&);
76 std::size_t operator()(T const&) const;
79 #if TEST_STD_VER >= 14
81 void swap(some_hash2<T>&, some_hash2<T>&) noexcept {}
90 some_alloc(const some_alloc&);
91 void deallocate(void*, unsigned) {}
93 typedef std::true_type propagate_on_container_swap;
102 some_alloc2(const some_alloc2&);
103 void deallocate(void*, unsigned) {}
105 typedef std::false_type propagate_on_container_swap;
106 typedef std::true_type is_always_equal;
112 typedef T value_type;
115 some_alloc3(const some_alloc3&);
116 void deallocate(void*, unsigned) {}
118 typedef std::false_type propagate_on_container_swap;
119 typedef std::false_type is_always_equal;
125 typedef std::pair<const MoveOnly, MoveOnly> MapType;
127 typedef std::unordered_map<MoveOnly, MoveOnly> C;
128 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
130 #if defined(_LIBCPP_VERSION)
132 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
133 std::equal_to<MoveOnly>, test_allocator<MapType>> C;
134 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
137 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
138 std::equal_to<MoveOnly>, other_allocator<MapType>> C;
139 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
141 #endif // _LIBCPP_VERSION
143 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
144 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
147 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
148 some_comp<MoveOnly>> C;
149 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
152 #if TEST_STD_VER >= 14
153 { // POCS allocator, throwable swap for hash, throwable swap for comp
154 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp <MoveOnly>, some_alloc <MapType>> C;
155 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
157 { // always equal allocator, throwable swap for hash, throwable swap for comp
158 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp <MoveOnly>, some_alloc2<MapType>> C;
159 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
161 { // POCS allocator, throwable swap for hash, nothrow swap for comp
162 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp2<MoveOnly>, some_alloc <MapType>> C;
163 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
165 { // always equal allocator, throwable swap for hash, nothrow swap for comp
166 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp2<MoveOnly>, some_alloc2<MapType>> C;
167 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
169 { // POCS allocator, nothrow swap for hash, throwable swap for comp
170 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp <MoveOnly>, some_alloc <MapType>> C;
171 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
173 { // always equal allocator, nothrow swap for hash, throwable swap for comp
174 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp <MoveOnly>, some_alloc2<MapType>> C;
175 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
177 { // POCS allocator, nothrow swap for hash, nothrow swap for comp
178 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc <MapType>> C;
179 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
181 { // always equal allocator, nothrow swap for hash, nothrow swap for comp
182 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc2<MapType>> C;
183 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
185 #if defined(_LIBCPP_VERSION)
186 { // NOT always equal allocator, nothrow swap for hash, nothrow swap for comp
187 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc3<MapType>> C;
188 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
190 #endif // _LIBCPP_VERSION