Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / containers / associative / map / map.special / swap_noexcept.pass.cpp
blob96f96f548a3573a9d0d9e3b68186826a9f5dc74e
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <map>
13 // void swap(map& c)
14 // noexcept(!allocator_type::propagate_on_container_swap::value ||
15 // __is_nothrow_swappable<allocator_type>::value);
17 // In C++17, the standard says that swap shall have:
18 // noexcept(allocator_traits<Allocator>::is_always_equal::value &&
19 // noexcept(swap(declval<Compare&>(), declval<Compare&>())));
21 // This tests a conforming extension
23 #include <map>
24 #include <utility>
25 #include <cassert>
27 #include "test_macros.h"
28 #include "MoveOnly.h"
29 #include "test_allocator.h"
31 template <class T>
32 struct some_comp
34 typedef T value_type;
36 some_comp() {}
37 some_comp(const some_comp&) {}
38 bool operator()(const T&, const T&) const { return false; }
41 template <class T>
42 struct some_comp2
44 typedef T value_type;
46 some_comp2() {}
47 some_comp2(const some_comp2&) {}
48 bool operator()(const T&, const T&) const { return false; }
51 #if TEST_STD_VER >= 14
52 template <typename T>
53 void swap(some_comp2<T>&, some_comp2<T>&) noexcept {}
54 #endif
56 template <class T>
57 struct some_alloc
59 typedef T value_type;
61 some_alloc() {}
62 some_alloc(const some_alloc&);
63 void deallocate(void*, unsigned) {}
65 typedef std::true_type propagate_on_container_swap;
68 template <class T>
69 struct some_alloc2
71 typedef T value_type;
73 some_alloc2() {}
74 some_alloc2(const some_alloc2&);
75 void deallocate(void*, unsigned) {}
77 typedef std::false_type propagate_on_container_swap;
78 typedef std::true_type is_always_equal;
81 template <class T>
82 struct some_alloc3
84 typedef T value_type;
86 some_alloc3() {}
87 some_alloc3(const some_alloc3&);
88 void deallocate(void*, unsigned) {}
90 typedef std::false_type propagate_on_container_swap;
91 typedef std::false_type is_always_equal;
94 int main(int, char**)
96 typedef std::pair<const MoveOnly, MoveOnly> V;
98 typedef std::map<MoveOnly, MoveOnly> C;
99 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
101 #if defined(_LIBCPP_VERSION)
103 typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C;
104 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
107 typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C;
108 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
110 #endif // _LIBCPP_VERSION
112 typedef std::map<MoveOnly, MoveOnly, some_comp<MoveOnly>> C;
113 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
116 #if TEST_STD_VER >= 14
117 { // POCS allocator, throwable swap for comp
118 typedef std::map<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <V>> C;
119 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
121 { // always equal allocator, throwable swap for comp
122 typedef std::map<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<V>> C;
123 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
125 { // POCS allocator, nothrow swap for comp
126 typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <V>> C;
127 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
129 { // always equal allocator, nothrow swap for comp
130 typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<V>> C;
131 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
133 #if defined(_LIBCPP_VERSION)
134 { // NOT always equal allocator, nothrow swap for comp
135 typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<V>> C;
136 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
138 #endif // _LIBCPP_VERSION
139 #endif
142 return 0;