| 1 | // -*- C++ -*- |
|---|---|
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___MEMORY_RANGES_DESTROY_H |
| 11 | #define _LIBCPP___MEMORY_RANGES_DESTROY_H |
| 12 | |
| 13 | #include <__concepts/destructible.h> |
| 14 | #include <__config> |
| 15 | #include <__iterator/incrementable_traits.h> |
| 16 | #include <__iterator/iterator_traits.h> |
| 17 | #include <__memory/concepts.h> |
| 18 | #include <__memory/destroy.h> |
| 19 | #include <__ranges/access.h> |
| 20 | #include <__ranges/concepts.h> |
| 21 | #include <__ranges/dangling.h> |
| 22 | #include <__utility/move.h> |
| 23 | |
| 24 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 25 | # pragma GCC system_header |
| 26 | #endif |
| 27 | |
| 28 | _LIBCPP_PUSH_MACROS |
| 29 | #include <__undef_macros> |
| 30 | |
| 31 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 32 | |
| 33 | #if _LIBCPP_STD_VER >= 20 |
| 34 | namespace ranges { |
| 35 | |
| 36 | // destroy |
| 37 | |
| 38 | struct __destroy { |
| 39 | template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel> |
| 40 | requires destructible<iter_value_t<_InputIterator>> |
| 41 | _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept { |
| 42 | return std::__destroy(std::move(__first), std::move(__last)); |
| 43 | } |
| 44 | |
| 45 | template <__nothrow_input_range _InputRange> |
| 46 | requires destructible<range_value_t<_InputRange>> |
| 47 | _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept { |
| 48 | return (*this)(ranges::begin(__range), ranges::end(__range)); |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | inline namespace __cpo { |
| 53 | inline constexpr auto destroy = __destroy{}; |
| 54 | } // namespace __cpo |
| 55 | |
| 56 | // destroy_n |
| 57 | |
| 58 | struct __destroy_n { |
| 59 | template <__nothrow_input_iterator _InputIterator> |
| 60 | requires destructible<iter_value_t<_InputIterator>> |
| 61 | _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator |
| 62 | operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept { |
| 63 | return std::destroy_n(std::move(__first), __n); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | inline namespace __cpo { |
| 68 | inline constexpr auto destroy_n = __destroy_n{}; |
| 69 | } // namespace __cpo |
| 70 | |
| 71 | } // namespace ranges |
| 72 | |
| 73 | #endif // _LIBCPP_STD_VER >= 20 |
| 74 | |
| 75 | _LIBCPP_END_NAMESPACE_STD |
| 76 | |
| 77 | _LIBCPP_POP_MACROS |
| 78 | |
| 79 | #endif // _LIBCPP___MEMORY_RANGES_DESTROY_H |
| 80 |