Path: blob/main/contrib/llvm-project/libcxx/include/__cxx03/__utility/swap.h
213799 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___CXX03___UTILITY_SWAP_H9#define _LIBCPP___CXX03___UTILITY_SWAP_H1011#include <__cxx03/__config>12#include <__cxx03/__type_traits/is_assignable.h>13#include <__cxx03/__type_traits/is_constructible.h>14#include <__cxx03/__type_traits/is_nothrow_assignable.h>15#include <__cxx03/__type_traits/is_nothrow_constructible.h>16#include <__cxx03/__type_traits/is_swappable.h>17#include <__cxx03/__utility/declval.h>18#include <__cxx03/__utility/move.h>19#include <__cxx03/cstddef>2021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)22# pragma GCC system_header23#endif2425_LIBCPP_PUSH_MACROS26#include <__cxx03/__undef_macros>2728_LIBCPP_BEGIN_NAMESPACE_STD2930template <class>31using __swap_result_t = void;3233template <class _Tp>34inline _LIBCPP_HIDE_FROM_ABI __swap_result_t<_Tp> swap(_Tp& __x, _Tp& __y) {35_Tp __t(std::move(__x));36__x = std::move(__y);37__y = std::move(__t);38}3940template <class _Tp, size_t _Np, __enable_if_t<__is_swappable_v<_Tp>, int> >41inline _LIBCPP_HIDE_FROM_ABI void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) {42for (size_t __i = 0; __i != _Np; ++__i) {43swap(__a[__i], __b[__i]);44}45}4647_LIBCPP_END_NAMESPACE_STD4849_LIBCPP_POP_MACROS5051#endif // _LIBCPP___CXX03___UTILITY_SWAP_H525354