1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // void swap(vector& 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>::propagate_on_container_swap::value ||
19 // allocator_traits<Allocator>::is_always_equal::value);
21 // This tests a conforming extension
27 #include "test_macros.h"
29 #include "test_allocator.h"
37 some_alloc(const some_alloc
&);
38 void deallocate(void*, unsigned) {}
40 typedef std::true_type propagate_on_container_swap
;
49 some_alloc2(const some_alloc2
&);
50 void deallocate(void*, unsigned) {}
52 typedef std::false_type propagate_on_container_swap
;
53 typedef std::true_type is_always_equal
;
59 typedef std::vector
<MoveOnly
> C
;
60 static_assert(noexcept(swap(std::declval
<C
&>(), std::declval
<C
&>())), "");
62 #if defined(_LIBCPP_VERSION)
64 typedef std::vector
<MoveOnly
, test_allocator
<MoveOnly
>> C
;
65 static_assert(noexcept(swap(std::declval
<C
&>(), std::declval
<C
&>())), "");
67 #endif // _LIBCPP_VERSION
69 typedef std::vector
<MoveOnly
, other_allocator
<MoveOnly
>> C
;
70 static_assert(noexcept(swap(std::declval
<C
&>(), std::declval
<C
&>())), "");
73 typedef std::vector
<MoveOnly
, some_alloc
<MoveOnly
>> C
;
74 #if TEST_STD_VER >= 14
75 // In C++14, if POCS is set, swapping the allocator is required not to throw
76 static_assert( noexcept(swap(std::declval
<C
&>(), std::declval
<C
&>())), "");
78 static_assert(!noexcept(swap(std::declval
<C
&>(), std::declval
<C
&>())), "");
81 #if TEST_STD_VER >= 14
83 typedef std::vector
<MoveOnly
, some_alloc2
<MoveOnly
>> C
;
84 // if the allocators are always equal, then the swap can be noexcept
85 static_assert( noexcept(swap(std::declval
<C
&>(), std::declval
<C
&>())), "");