codekingpro/portable-devtools
114k
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX___UTILITY_SWAP_H11#define _LIBCUDACXX___UTILITY_SWAP_H12 13#ifndef __cuda_std__14#include <__config>15#endif // __cuda_std__16 17#include "../__type_traits/enable_if.h"18#include "../__type_traits/is_move_assignable.h"19#include "../__type_traits/is_move_constructible.h"20#include "../__type_traits/is_nothrow_move_assignable.h"21#include "../__type_traits/is_nothrow_move_constructible.h"22#include "../__type_traits/is_swappable.h"23#include "../__utility/move.h"24#include "../cstddef"25 26#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)27# pragma GCC system_header28#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)29# pragma clang system_header30#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)31# pragma system_header32#endif // no system header33 34_LIBCUDACXX_BEGIN_NAMESPACE_STD35 36template <class _Tp>37inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1138__swap_result_t<_Tp>39swap(_Tp& __x, _Tp& __y) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)40 && _LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp)) {41 _Tp __t(_CUDA_VSTD::move(__x));42 __x = _CUDA_VSTD::move(__y);43 __y = _CUDA_VSTD::move(__t);44}45 46template <class _Tp, size_t _Np>47inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1148__enable_if_t<__is_swappable<_Tp>::value>49swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) noexcept(__is_nothrow_swappable<_Tp>::value) {50 for (size_t __i = 0; __i != _Np; ++__i) {51 swap(__a[__i], __b[__i]);52 }53}54 55_LIBCUDACXX_END_NAMESPACE_STD56 57#endif // _LIBCUDACXX___UTILITY_SWAP_H58 