Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __memory / ranges_construct_at.h
blobed800f4a75b41a9288f68dff86639345a8ae7aa6
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 <__iterator/incrementable_traits.h>
16 #include <__iterator/iterator_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>
27 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28 # pragma GCC system_header
29 #endif
31 _LIBCPP_PUSH_MACROS
32 #include <__undef_macros>
34 _LIBCPP_BEGIN_NAMESPACE_STD
36 #if _LIBCPP_STD_VER >= 20
37 namespace ranges {
39 // construct_at
41 namespace __construct_at {
43 struct __fn {
44 template<class _Tp, class... _Args, class = decltype(
45 ::new (std::declval<void*>()) _Tp(std::declval<_Args>()...)
47 _LIBCPP_HIDE_FROM_ABI
48 constexpr _Tp* operator()(_Tp* __location, _Args&& ...__args) const {
49 return _VSTD::construct_at(__location, _VSTD::forward<_Args>(__args)...);
53 } // namespace __construct_at
55 inline namespace __cpo {
56 inline constexpr auto construct_at = __construct_at::__fn{};
57 } // namespace __cpo
59 // destroy_at
61 namespace __destroy_at {
63 struct __fn {
64 template <destructible _Tp>
65 _LIBCPP_HIDE_FROM_ABI
66 constexpr void operator()(_Tp* __location) const noexcept {
67 _VSTD::destroy_at(__location);
71 } // namespace __destroy_at
73 inline namespace __cpo {
74 inline constexpr auto destroy_at = __destroy_at::__fn{};
75 } // namespace __cpo
77 // destroy
79 namespace __destroy {
81 struct __fn {
82 template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel>
83 requires destructible<iter_value_t<_InputIterator>>
84 _LIBCPP_HIDE_FROM_ABI
85 constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept {
86 return _VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last));
89 template <__nothrow_input_range _InputRange>
90 requires destructible<range_value_t<_InputRange>>
91 _LIBCPP_HIDE_FROM_ABI
92 constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept {
93 return (*this)(ranges::begin(__range), ranges::end(__range));
97 } // namespace __destroy
99 inline namespace __cpo {
100 inline constexpr auto destroy = __destroy::__fn{};
101 } // namespace __cpo
103 // destroy_n
105 namespace __destroy_n {
107 struct __fn {
108 template <__nothrow_input_iterator _InputIterator>
109 requires destructible<iter_value_t<_InputIterator>>
110 _LIBCPP_HIDE_FROM_ABI
111 constexpr _InputIterator operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept {
112 return _VSTD::destroy_n(_VSTD::move(__first), __n);
116 } // namespace __destroy_n
118 inline namespace __cpo {
119 inline constexpr auto destroy_n = __destroy_n::__fn{};
120 } // namespace __cpo
122 } // namespace ranges
124 #endif // _LIBCPP_STD_VER >= 20
126 _LIBCPP_END_NAMESPACE_STD
128 _LIBCPP_POP_MACROS
130 #endif // _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H