File indexing completed on 2026-05-03 08:13:45
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___UTILITY_SWAP_H
0010 #define _LIBCPP___CXX03___UTILITY_SWAP_H
0011
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__type_traits/is_assignable.h>
0014 #include <__cxx03/__type_traits/is_constructible.h>
0015 #include <__cxx03/__type_traits/is_nothrow_assignable.h>
0016 #include <__cxx03/__type_traits/is_nothrow_constructible.h>
0017 #include <__cxx03/__type_traits/is_swappable.h>
0018 #include <__cxx03/__utility/declval.h>
0019 #include <__cxx03/__utility/move.h>
0020 #include <__cxx03/cstddef>
0021
0022 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0023 # pragma GCC system_header
0024 #endif
0025
0026 _LIBCPP_PUSH_MACROS
0027 #include <__cxx03/__undef_macros>
0028
0029 _LIBCPP_BEGIN_NAMESPACE_STD
0030
0031 #ifndef _LIBCPP_CXX03_LANG
0032 template <class _Tp>
0033 using __swap_result_t = __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>;
0034 #else
0035 template <class>
0036 using __swap_result_t = void;
0037 #endif
0038
0039 template <class _Tp>
0040 inline _LIBCPP_HIDE_FROM_ABI __swap_result_t<_Tp> _LIBCPP_CONSTEXPR_SINCE_CXX20 swap(_Tp& __x, _Tp& __y)
0041 _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value&& is_nothrow_move_assignable<_Tp>::value) {
0042 _Tp __t(std::move(__x));
0043 __x = std::move(__y);
0044 __y = std::move(__t);
0045 }
0046
0047 template <class _Tp, size_t _Np, __enable_if_t<__is_swappable_v<_Tp>, int> >
0048 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np])
0049 _NOEXCEPT_(__is_nothrow_swappable_v<_Tp>) {
0050 for (size_t __i = 0; __i != _Np; ++__i) {
0051 swap(__a[__i], __b[__i]);
0052 }
0053 }
0054
0055 _LIBCPP_END_NAMESPACE_STD
0056
0057 _LIBCPP_POP_MACROS
0058
0059 #endif