File indexing completed on 2025-01-18 10:09:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_VIEW_INDIRECT_HPP
0015 #define RANGES_V3_VIEW_INDIRECT_HPP
0016
0017 #include <iterator>
0018 #include <type_traits>
0019 #include <utility>
0020
0021 #include <meta/meta.hpp>
0022
0023 #include <range/v3/range_fwd.hpp>
0024
0025 #include <range/v3/range/access.hpp>
0026 #include <range/v3/range/traits.hpp>
0027 #include <range/v3/utility/move.hpp>
0028 #include <range/v3/utility/static_const.hpp>
0029 #include <range/v3/view/adaptor.hpp>
0030 #include <range/v3/view/view.hpp>
0031
0032 #include <range/v3/detail/prologue.hpp>
0033
0034 namespace ranges
0035 {
0036
0037
0038 template<typename Rng>
0039 struct indirect_view : view_adaptor<indirect_view<Rng>, Rng>
0040 {
0041 private:
0042 friend range_access;
0043
0044 template<bool IsConst>
0045 struct adaptor : adaptor_base
0046 {
0047 friend adaptor<!IsConst>;
0048 using CRng = meta::const_if_c<IsConst, Rng>;
0049
0050 adaptor() = default;
0051 template(bool Other)(
0052 requires IsConst && CPP_NOT(Other))
0053 constexpr adaptor(adaptor<Other>) noexcept
0054 {}
0055
0056
0057 constexpr auto CPP_auto_fun(read)(iterator_t<CRng> const &it)(const)
0058 (
0059 return **it
0060 )
0061 constexpr auto CPP_auto_fun(iter_move)(iterator_t<CRng> const &it)(const)
0062 (
0063 return ranges::iter_move(*it)
0064 )
0065
0066 };
0067
0068 CPP_member
0069 constexpr auto begin_adaptor() noexcept
0070 -> CPP_ret(adaptor<false>)(
0071 requires (!simple_view<Rng>()))
0072 {
0073 return {};
0074 }
0075 CPP_member
0076 constexpr auto begin_adaptor() const noexcept
0077 -> CPP_ret(adaptor<true>)(
0078 requires range<Rng const>)
0079 {
0080 return {};
0081 }
0082
0083 CPP_member
0084 constexpr auto end_adaptor() noexcept
0085 -> CPP_ret(adaptor<false>)(
0086 requires (!simple_view<Rng>()))
0087 {
0088 return {};
0089 }
0090 CPP_member
0091 constexpr auto end_adaptor() const noexcept
0092 -> CPP_ret(adaptor<true>)(
0093 requires range<Rng const>)
0094 {
0095 return {};
0096 }
0097
0098 public:
0099 indirect_view() = default;
0100 constexpr explicit indirect_view(Rng rng)
0101 : indirect_view::view_adaptor{detail::move(rng)}
0102 {}
0103 CPP_auto_member
0104 constexpr auto CPP_fun(size)()(const
0105 requires sized_range<Rng const>)
0106 {
0107 return ranges::size(this->base());
0108 }
0109 CPP_auto_member
0110 constexpr auto CPP_fun(size)()(
0111 requires sized_range<Rng>)
0112 {
0113 return ranges::size(this->base());
0114 }
0115 };
0116
0117 template<typename Rng>
0118 RANGES_INLINE_VAR constexpr bool enable_borrowed_range<indirect_view<Rng>> =
0119 enable_borrowed_range<Rng>;
0120
0121 #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
0122 template<typename Rng>
0123 indirect_view(Rng &&)
0124 -> indirect_view<views::all_t<Rng>>;
0125 #endif
0126
0127 namespace views
0128 {
0129 struct indirect_fn
0130 {
0131 template(typename Rng)(
0132 requires viewable_range<Rng> AND input_range<Rng> AND
0133
0134
0135
0136 ((bool)indirectly_readable<range_value_t<Rng>>))
0137
0138 constexpr auto operator()(Rng && rng) const
0139 {
0140 return indirect_view<all_t<Rng>>{all(static_cast<Rng &&>(rng))};
0141 }
0142 };
0143
0144
0145
0146 RANGES_INLINE_VARIABLE(view_closure<indirect_fn>, indirect)
0147 }
0148
0149 }
0150
0151 #include <range/v3/detail/epilogue.hpp>
0152
0153 #include <range/v3/detail/satisfy_boost_range.hpp>
0154 RANGES_SATISFY_BOOST_RANGE(::ranges::indirect_view)
0155
0156 #endif