[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / libcxx / include / __memory / ranges_construct_at.h
blob9b0edb7c2562d1a56622a72cb059f7dc5e6e5fc4
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H
11 #define _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H
13 #include <__concepts/destructible.h>
14 #include <__config>
15 #include <__function_like.h>
16 #include <__iterator/incrementable_traits.h>
17 #include <__iterator/readable_traits.h>
18 #include <__memory/concepts.h>
19 #include <__memory/construct_at.h>
20 #include <__ranges/access.h>
21 #include <__ranges/concepts.h>
22 #include <__ranges/dangling.h>
23 #include <__utility/declval.h>
24 #include <__utility/forward.h>
25 #include <__utility/move.h>
27 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28 #pragma GCC system_header
29 #endif
31 _LIBCPP_BEGIN_NAMESPACE_STD
33 #if !defined(_LIBCPP_HAS_NO_RANGES)
34 namespace ranges {
36 // construct_at
38 namespace __construct_at {
40 struct __fn final : private __function_like {
41 _LIBCPP_HIDE_FROM_ABI constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
43 template<class _Tp, class... _Args, class = decltype(
44 ::new (declval<void*>()) _Tp(declval<_Args>()...)
46 _LIBCPP_HIDE_FROM_ABI
47 constexpr _Tp* operator()(_Tp* __location, _Args&& ...__args) const {
48 return _VSTD::construct_at(__location, _VSTD::forward<_Args>(__args)...);
52 } // namespace __construct_at
54 inline namespace __cpo {
55 inline constexpr auto construct_at = __construct_at::__fn(__function_like::__tag());
56 } // namespace __cpo
58 // destroy_at
60 namespace __destroy_at {
62 struct __fn final : private __function_like {
63 _LIBCPP_HIDE_FROM_ABI constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
65 template <destructible _Tp>
66 _LIBCPP_HIDE_FROM_ABI
67 constexpr void operator()(_Tp* __location) const noexcept {
68 _VSTD::destroy_at(__location);
72 } // namespace __destroy_at
74 inline namespace __cpo {
75 inline constexpr auto destroy_at = __destroy_at::__fn(__function_like::__tag());
76 } // namespace __cpo
78 // destroy
80 namespace __destroy {
82 struct __fn final : private __function_like {
83 _LIBCPP_HIDE_FROM_ABI constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
85 template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel>
86 requires destructible<iter_value_t<_InputIterator>>
87 _LIBCPP_HIDE_FROM_ABI
88 constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept {
89 return _VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last));
92 template <__nothrow_input_range _InputRange>
93 requires destructible<range_value_t<_InputRange>>
94 _LIBCPP_HIDE_FROM_ABI
95 constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept {
96 return (*this)(ranges::begin(__range), ranges::end(__range));
100 } // namespace __destroy
102 inline namespace __cpo {
103 inline constexpr auto destroy = __destroy::__fn(__function_like::__tag());
104 } // namespace __cpo
106 // destroy_n
108 namespace __destroy_n {
110 struct __fn final : private __function_like {
111 _LIBCPP_HIDE_FROM_ABI constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
113 template <__nothrow_input_iterator _InputIterator>
114 requires destructible<iter_value_t<_InputIterator>>
115 _LIBCPP_HIDE_FROM_ABI
116 constexpr _InputIterator operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept {
117 return _VSTD::destroy_n(_VSTD::move(__first), __n);
121 } // namespace __destroy_n
123 inline namespace __cpo {
124 inline constexpr auto destroy_n = __destroy_n::__fn(__function_like::__tag());
125 } // namespace __cpo
127 } // namespace ranges
128 #endif // !defined(_LIBCPP_HAS_NO_RANGES)
130 _LIBCPP_END_NAMESPACE_STD
132 #endif // _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H