Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __ranges / as_rvalue_view.h
blob295aa94ed9fe40bd5ea4e1d85f2ca30ea9740cda
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___RANGES_AS_RVALUE_H
10 #define _LIBCPP___RANGES_AS_RVALUE_H
12 #include <__concepts/constructible.h>
13 #include <__concepts/same_as.h>
14 #include <__config>
15 #include <__iterator/move_iterator.h>
16 #include <__iterator/move_sentinel.h>
17 #include <__ranges/access.h>
18 #include <__ranges/all.h>
19 #include <__ranges/concepts.h>
20 #include <__ranges/enable_borrowed_range.h>
21 #include <__ranges/range_adaptor.h>
22 #include <__ranges/size.h>
23 #include <__ranges/view_interface.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_PUSH_MACROS
32 #include <__undef_macros>
34 #if _LIBCPP_STD_VER >= 23
36 _LIBCPP_BEGIN_NAMESPACE_STD
38 namespace ranges {
39 template <view _View>
40 requires input_range<_View>
41 class as_rvalue_view : public view_interface<as_rvalue_view<_View>> {
42 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
44 public:
45 _LIBCPP_HIDE_FROM_ABI as_rvalue_view()
46 requires default_initializable<_View>
47 = default;
49 _LIBCPP_HIDE_FROM_ABI constexpr explicit as_rvalue_view(_View __base) : __base_(std::move(__base)) {}
51 _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
52 requires copy_constructible<_View>
54 return __base_;
57 _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); }
59 _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
60 requires(!__simple_view<_View>)
62 return move_iterator(ranges::begin(__base_));
65 _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
66 requires range<const _View>
68 return move_iterator(ranges::begin(__base_));
71 _LIBCPP_HIDE_FROM_ABI constexpr auto end()
72 requires(!__simple_view<_View>)
74 if constexpr (common_range<_View>) {
75 return move_iterator(ranges::end(__base_));
76 } else {
77 return move_sentinel(ranges::end(__base_));
81 _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
82 requires range<const _View>
84 if constexpr (common_range<const _View>) {
85 return move_iterator(ranges::end(__base_));
86 } else {
87 return move_sentinel(ranges::end(__base_));
91 _LIBCPP_HIDE_FROM_ABI constexpr auto size()
92 requires sized_range<_View>
94 return ranges::size(__base_);
97 _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
98 requires sized_range<const _View>
100 return ranges::size(__base_);
104 template <class _Range>
105 as_rvalue_view(_Range&&) -> as_rvalue_view<views::all_t<_Range>>;
107 template <class _View>
108 inline constexpr bool enable_borrowed_range<as_rvalue_view<_View>> = enable_borrowed_range<_View>;
110 namespace views {
111 namespace __as_rvalue {
112 struct __fn : __range_adaptor_closure<__fn> {
113 template <class _Range>
114 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range) const
115 noexcept(noexcept(/**/ as_rvalue_view(std::forward<_Range>(__range))))
116 -> decltype(/*--*/ as_rvalue_view(std::forward<_Range>(__range))) {
117 return /*-------------*/ as_rvalue_view(std::forward<_Range>(__range));
120 template <class _Range>
121 requires same_as<range_rvalue_reference_t<_Range>, range_reference_t<_Range>>
122 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range) const
123 noexcept(noexcept(/**/ views::all(std::forward<_Range>(__range))))
124 -> decltype(/*--*/ views::all(std::forward<_Range>(__range))) {
125 return /*-------------*/ views::all(std::forward<_Range>(__range));
128 } // namespace __as_rvalue
130 inline namespace __cpo {
131 inline constexpr auto as_rvalue = __as_rvalue::__fn{};
132 } // namespace __cpo
133 } // namespace views
134 } // namespace ranges
136 _LIBCPP_END_NAMESPACE_STD
138 #endif // _LIBCPP_STD_VER >= 23
140 _LIBCPP_POP_MACROS
142 #endif // _LIBCPP___RANGES_AS_RVALUE_H