Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:07

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___UTILITY_SWAP_H
0010 #define _LIBCPP___UTILITY_SWAP_H
0011 
0012 #include <__config>
0013 #include <__cstddef/size_t.h>
0014 #include <__type_traits/enable_if.h>
0015 #include <__type_traits/is_assignable.h>
0016 #include <__type_traits/is_constructible.h>
0017 #include <__type_traits/is_nothrow_assignable.h>
0018 #include <__type_traits/is_nothrow_constructible.h>
0019 #include <__type_traits/is_swappable.h>
0020 #include <__utility/declval.h>
0021 #include <__utility/move.h>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_PUSH_MACROS
0028 #include <__undef_macros>
0029 
0030 _LIBCPP_BEGIN_NAMESPACE_STD
0031 
0032 #ifndef _LIBCPP_CXX03_LANG
0033 template <class _Tp>
0034 using __swap_result_t _LIBCPP_NODEBUG =
0035     __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>;
0036 #else
0037 template <class>
0038 using __swap_result_t _LIBCPP_NODEBUG = void;
0039 #endif
0040 
0041 template <class _Tp>
0042 inline _LIBCPP_HIDE_FROM_ABI __swap_result_t<_Tp> _LIBCPP_CONSTEXPR_SINCE_CXX20 swap(_Tp& __x, _Tp& __y)
0043     _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value&& is_nothrow_move_assignable<_Tp>::value) {
0044   _Tp __t(std::move(__x));
0045   __x = std::move(__y);
0046   __y = std::move(__t);
0047 }
0048 
0049 template <class _Tp, size_t _Np, __enable_if_t<__is_swappable_v<_Tp>, int> >
0050 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np])
0051     _NOEXCEPT_(__is_nothrow_swappable_v<_Tp>) {
0052   for (size_t __i = 0; __i != _Np; ++__i) {
0053     swap(__a[__i], __b[__i]);
0054   }
0055 }
0056 
0057 _LIBCPP_END_NAMESPACE_STD
0058 
0059 _LIBCPP_POP_MACROS
0060 
0061 #endif // _LIBCPP___UTILITY_SWAP_H