Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.nonmembers / string.special / swap_noexcept.pass.cpp
blobe3465400fbae48a9e6470e365c804342f5164878
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 // <string>
13 // void swap(basic_string& c)
14 // noexcept(!allocator_type::propagate_on_container_swap::value ||
15 // __is_nothrow_swappable<allocator_type>::value); // constexpr since C++20
17 // In C++17, the standard says that swap shall have:
18 // noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
19 // allocator_traits<Allocator>::is_always_equal::value); // constexpr since C++20
21 // This tests a conforming extension
23 #include <string>
24 #include <utility>
25 #include <cassert>
27 #include "test_macros.h"
28 #include "test_allocator.h"
30 template <class T>
31 struct some_alloc {
32 typedef T value_type;
34 some_alloc() {}
35 some_alloc(const some_alloc&);
36 T* allocate(std::size_t);
37 void deallocate(void*, unsigned) {}
38 typedef std::true_type propagate_on_container_swap;
41 template <class T>
42 struct some_alloc2 {
43 typedef T value_type;
45 some_alloc2() {}
46 some_alloc2(const some_alloc2&);
47 T* allocate(std::size_t);
48 void deallocate(void*, unsigned) {}
50 typedef std::false_type propagate_on_container_swap;
51 typedef std::true_type is_always_equal;
54 int main(int, char**) {
56 typedef std::string C;
57 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
59 #if defined(_LIBCPP_VERSION)
61 typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
62 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
64 #endif // _LIBCPP_VERSION
66 typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
67 #if TEST_STD_VER >= 14
68 // In C++14, if POCS is set, swapping the allocator is required not to throw
69 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
70 #else
71 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
72 #endif
74 #if TEST_STD_VER >= 14
76 typedef std::basic_string<char, std::char_traits<char>, some_alloc2<char>> C;
77 // if the allocators are always equal, then the swap can be noexcept
78 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
80 #endif
82 return 0;