Path: blob/main/contrib/llvm-project/libcxx/include/__memory/destroy.h
213766 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___MEMORY_DESTROY_H9#define _LIBCPP___MEMORY_DESTROY_H1011#include <__config>12#include <__memory/addressof.h>13#include <__memory/allocator_traits.h>14#include <__memory/construct_at.h>15#include <__utility/move.h>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_PUSH_MACROS22#include <__undef_macros>2324_LIBCPP_BEGIN_NAMESPACE_STD2526template <class _ForwardIterator>27_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator28__destroy(_ForwardIterator __first, _ForwardIterator __last) {29for (; __first != __last; ++__first)30std::__destroy_at(std::addressof(*__first));31return __first;32}3334template <class _BidirectionalIterator>35_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator36__reverse_destroy(_BidirectionalIterator __first, _BidirectionalIterator __last) {37while (__last != __first) {38--__last;39std::__destroy_at(std::addressof(*__last));40}41return __last;42}4344// Destroy all elements in [__first, __last) from left to right using allocator destruction.45template <class _Alloc, class _Iter, class _Sent>46_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void47__allocator_destroy(_Alloc& __alloc, _Iter __first, _Sent __last) {48for (; __first != __last; ++__first)49allocator_traits<_Alloc>::destroy(__alloc, std::addressof(*__first));50}5152#if _LIBCPP_STD_VER >= 1753template <class _ForwardIterator>54_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy(_ForwardIterator __first, _ForwardIterator __last) {55(void)std::__destroy(std::move(__first), std::move(__last));56}5758template <class _ForwardIterator, class _Size>59_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {60for (; __n > 0; (void)++__first, --__n)61std::__destroy_at(std::addressof(*__first));62return __first;63}64#endif6566_LIBCPP_END_NAMESPACE_STD6768_LIBCPP_POP_MACROS6970#endif // _LIBCPP___MEMORY_DESTROY_H717273