// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of libcu++, the C++ Standard Library for your entire system, // under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// #ifndef _LIBCUDACXX___MEMORY_DESTRUCT_N_H #define _LIBCUDACXX___MEMORY_DESTRUCT_N_H #include #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) # pragma GCC system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) # pragma clang system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) # pragma system_header #endif // no system header #include #include #include _LIBCUDACXX_BEGIN_NAMESPACE_STD struct __destruct_n { private: size_t __size_; template _LIBCUDACXX_INLINE_VISIBILITY void __process(_Tp* __p, false_type) noexcept { for (size_t __i = 0; __i < __size_; ++__i, ++__p) { __p->~_Tp(); } } template _LIBCUDACXX_INLINE_VISIBILITY void __process(_Tp*, true_type) noexcept {} _LIBCUDACXX_INLINE_VISIBILITY void __incr(false_type) noexcept { ++__size_; } _LIBCUDACXX_INLINE_VISIBILITY void __incr(true_type) noexcept {} _LIBCUDACXX_INLINE_VISIBILITY void __set(size_t __s, false_type) noexcept { __size_ = __s; } _LIBCUDACXX_INLINE_VISIBILITY void __set(size_t, true_type) noexcept {} public: _LIBCUDACXX_INLINE_VISIBILITY explicit __destruct_n(size_t __s) noexcept : __size_(__s) {} template _LIBCUDACXX_INLINE_VISIBILITY void __incr() noexcept { __incr(integral_constant::value>()); } template _LIBCUDACXX_INLINE_VISIBILITY void __set(size_t __s, _Tp*) noexcept { __set(__s, integral_constant::value>()); } template _LIBCUDACXX_INLINE_VISIBILITY void operator()(_Tp* __p) noexcept { __process(__p, integral_constant::value>()); } }; _LIBCUDACXX_END_NAMESPACE_STD #endif // _LIBCUDACXX___MEMORY_DESTRUCT_N_H