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_CONSTRUCT_AT_H 11 #define _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H 12 13 #include <__concepts/destructible.h> 14 #include <__config> 15 #include <__iterator/incrementable_traits.h> 16 #include <__iterator/readable_traits.h> 17 #include <__memory/concepts.h> 18 #include <__memory/construct_at.h> 19 #include <__ranges/access.h> 20 #include <__ranges/concepts.h> 21 #include <__ranges/dangling.h> 22 #include <__utility/declval.h> 23 #include <__utility/forward.h> 24 #include <__utility/move.h> 25 26 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 27 #pragma GCC system_header 28 #endif 29 30 _LIBCPP_BEGIN_NAMESPACE_STD 31 32 #if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 33 namespace ranges { 34 35 // construct_at 36 37 namespace __construct_at { 38 39 struct __fn { 40 template<class _Tp, class... _Args, class = decltype( 41 ::new (declval<void*>()) _Tp(declval<_Args>()...) 42 )> 43 _LIBCPP_HIDE_FROM_ABI 44 constexpr _Tp* operator()(_Tp* __location, _Args&& ...__args) const { 45 return _VSTD::construct_at(__location, _VSTD::forward<_Args>(__args)...); 46 } 47 }; 48 49 } // namespace __construct_at 50 51 inline namespace __cpo { 52 inline constexpr auto construct_at = __construct_at::__fn{}; 53 } // namespace __cpo 54 55 // destroy_at 56 57 namespace __destroy_at { 58 59 struct __fn { 60 template <destructible _Tp> 61 _LIBCPP_HIDE_FROM_ABI 62 constexpr void operator()(_Tp* __location) const noexcept { 63 _VSTD::destroy_at(__location); 64 } 65 }; 66 67 } // namespace __destroy_at 68 69 inline namespace __cpo { 70 inline constexpr auto destroy_at = __destroy_at::__fn{}; 71 } // namespace __cpo 72 73 // destroy 74 75 namespace __destroy { 76 77 struct __fn { 78 template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel> 79 requires destructible<iter_value_t<_InputIterator>> 80 _LIBCPP_HIDE_FROM_ABI 81 constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept { 82 return _VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last)); 83 } 84 85 template <__nothrow_input_range _InputRange> 86 requires destructible<range_value_t<_InputRange>> 87 _LIBCPP_HIDE_FROM_ABI 88 constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept { 89 return (*this)(ranges::begin(__range), ranges::end(__range)); 90 } 91 }; 92 93 } // namespace __destroy 94 95 inline namespace __cpo { 96 inline constexpr auto destroy = __destroy::__fn{}; 97 } // namespace __cpo 98 99 // destroy_n 100 101 namespace __destroy_n { 102 103 struct __fn { 104 template <__nothrow_input_iterator _InputIterator> 105 requires destructible<iter_value_t<_InputIterator>> 106 _LIBCPP_HIDE_FROM_ABI 107 constexpr _InputIterator operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept { 108 return _VSTD::destroy_n(_VSTD::move(__first), __n); 109 } 110 }; 111 112 } // namespace __destroy_n 113 114 inline namespace __cpo { 115 inline constexpr auto destroy_n = __destroy_n::__fn{}; 116 } // namespace __cpo 117 118 } // namespace ranges 119 120 #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 121 122 _LIBCPP_END_NAMESPACE_STD 123 124 #endif // _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H 125