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