Path: blob/main/contrib/llvm-project/libcxx/include/__utility/swap.h
35235 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___UTILITY_SWAP_H9#define _LIBCPP___UTILITY_SWAP_H1011#include <__config>12#include <__type_traits/is_assignable.h>13#include <__type_traits/is_constructible.h>14#include <__type_traits/is_nothrow_assignable.h>15#include <__type_traits/is_nothrow_constructible.h>16#include <__type_traits/is_swappable.h>17#include <__utility/declval.h>18#include <__utility/move.h>19#include <cstddef>2021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)22# pragma GCC system_header23#endif2425_LIBCPP_PUSH_MACROS26#include <__undef_macros>2728_LIBCPP_BEGIN_NAMESPACE_STD2930#ifndef _LIBCPP_CXX03_LANG31template <class _Tp>32using __swap_result_t = __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>;33#else34template <class>35using __swap_result_t = void;36#endif3738template <class _Tp>39inline _LIBCPP_HIDE_FROM_ABI __swap_result_t<_Tp> _LIBCPP_CONSTEXPR_SINCE_CXX20 swap(_Tp& __x, _Tp& __y)40_NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value&& is_nothrow_move_assignable<_Tp>::value) {41_Tp __t(std::move(__x));42__x = std::move(__y);43__y = std::move(__t);44}4546template <class _Tp, size_t _Np, __enable_if_t<__is_swappable_v<_Tp>, int> >47inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np])48_NOEXCEPT_(__is_nothrow_swappable_v<_Tp>) {49for (size_t __i = 0; __i != _Np; ++__i) {50swap(__a[__i], __b[__i]);51}52}5354_LIBCPP_END_NAMESPACE_STD5556_LIBCPP_POP_MACROS5758#endif // _LIBCPP___UTILITY_SWAP_H596061