xref: /openbsd-src/gnu/llvm/libcxx/include/__memory/swap_allocator.h (revision 4bdff4bed0e3d54e55670334c7d0077db4170f86)
1*4bdff4beSrobert //===----------------------------------------------------------------------===//
2*4bdff4beSrobert //
3*4bdff4beSrobert // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*4bdff4beSrobert // See https://llvm.org/LICENSE.txt for license information.
5*4bdff4beSrobert // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*4bdff4beSrobert //
7*4bdff4beSrobert //===----------------------------------------------------------------------===//
8*4bdff4beSrobert 
9*4bdff4beSrobert #ifndef _LIBCPP___MEMORY_SWAP_ALLOCATOR_H
10*4bdff4beSrobert #define _LIBCPP___MEMORY_SWAP_ALLOCATOR_H
11*4bdff4beSrobert 
12*4bdff4beSrobert #include <__config>
13*4bdff4beSrobert #include <__memory/allocator_traits.h>
14*4bdff4beSrobert #include <__type_traits/integral_constant.h>
15*4bdff4beSrobert #include <__type_traits/is_swappable.h>
16*4bdff4beSrobert #include <__utility/swap.h>
17*4bdff4beSrobert 
18*4bdff4beSrobert #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19*4bdff4beSrobert #  pragma GCC system_header
20*4bdff4beSrobert #endif
21*4bdff4beSrobert 
22*4bdff4beSrobert _LIBCPP_BEGIN_NAMESPACE_STD
23*4bdff4beSrobert 
24*4bdff4beSrobert template <typename _Alloc>
__swap_allocator(_Alloc & __a1,_Alloc & __a2,true_type)25*4bdff4beSrobert _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swap_allocator(_Alloc& __a1, _Alloc& __a2, true_type)
26*4bdff4beSrobert #if _LIBCPP_STD_VER > 11
27*4bdff4beSrobert     _NOEXCEPT
28*4bdff4beSrobert #else
29*4bdff4beSrobert     _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
30*4bdff4beSrobert #endif
31*4bdff4beSrobert {
32*4bdff4beSrobert   using _VSTD::swap;
33*4bdff4beSrobert   swap(__a1, __a2);
34*4bdff4beSrobert }
35*4bdff4beSrobert 
36*4bdff4beSrobert template <typename _Alloc>
37*4bdff4beSrobert inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
__swap_allocator(_Alloc &,_Alloc &,false_type)38*4bdff4beSrobert __swap_allocator(_Alloc&, _Alloc&, false_type) _NOEXCEPT {}
39*4bdff4beSrobert 
40*4bdff4beSrobert template <typename _Alloc>
__swap_allocator(_Alloc & __a1,_Alloc & __a2)41*4bdff4beSrobert inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swap_allocator(_Alloc& __a1, _Alloc& __a2)
42*4bdff4beSrobert #if _LIBCPP_STD_VER > 11
43*4bdff4beSrobert     _NOEXCEPT
44*4bdff4beSrobert #else
45*4bdff4beSrobert     _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
46*4bdff4beSrobert #endif
47*4bdff4beSrobert {
48*4bdff4beSrobert   _VSTD::__swap_allocator(
49*4bdff4beSrobert       __a1, __a2, integral_constant<bool, allocator_traits<_Alloc>::propagate_on_container_swap::value>());
50*4bdff4beSrobert }
51*4bdff4beSrobert 
52*4bdff4beSrobert _LIBCPP_END_NAMESPACE_STD
53*4bdff4beSrobert 
54*4bdff4beSrobert #endif // _LIBCPP___MEMORY_SWAP_ALLOCATOR_H
55