File indexing completed on 2025-01-18 10:09:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_VIEW_REF_HPP
0015 #define RANGES_V3_VIEW_REF_HPP
0016
0017 #include <concepts/concepts.hpp>
0018
0019 #include <range/v3/range_fwd.hpp>
0020
0021 #include <range/v3/range/access.hpp>
0022 #include <range/v3/range/primitives.hpp>
0023 #include <range/v3/range/traits.hpp>
0024 #include <range/v3/utility/addressof.hpp>
0025 #include <range/v3/view/interface.hpp>
0026
0027 #include <range/v3/detail/prologue.hpp>
0028
0029 namespace ranges
0030 {
0031 template<typename Rng>
0032 struct ref_view;
0033
0034 template<typename Rng>
0035 RANGES_INLINE_VAR constexpr bool enable_borrowed_range<ref_view<Rng>> = true;
0036
0037
0038
0039 template<typename Rng>
0040 struct ref_view : view_interface<ref_view<Rng>, range_cardinality<Rng>::value>
0041 {
0042 private:
0043 CPP_assert(range<Rng>);
0044 static_assert(std::is_object<Rng>::value, "");
0045 Rng * rng_ = nullptr;
0046 public:
0047 constexpr ref_view() noexcept = default;
0048 constexpr ref_view(Rng & rng) noexcept
0049 : rng_(detail::addressof(rng))
0050 {}
0051 constexpr Rng & base() const noexcept
0052 {
0053 return *rng_;
0054 }
0055 constexpr iterator_t<Rng> begin() const noexcept(noexcept(ranges::begin(*rng_)))
0056 {
0057 return ranges::begin(*rng_);
0058 }
0059 constexpr sentinel_t<Rng> end() const noexcept(noexcept(ranges::end(*rng_)))
0060 {
0061 return ranges::end(*rng_);
0062 }
0063 CPP_member
0064 constexpr auto empty() const noexcept(noexcept(ranges::empty(*rng_)))
0065 -> CPP_ret(bool)(
0066 requires detail::can_empty_<Rng>)
0067 {
0068 return ranges::empty(*rng_);
0069 }
0070 CPP_auto_member
0071 constexpr auto CPP_fun(size)()(const
0072 noexcept(noexcept(ranges::size(*rng_)))
0073 requires sized_range<Rng>)
0074 {
0075 return ranges::size(*rng_);
0076 }
0077 CPP_auto_member
0078 constexpr auto CPP_fun(data)()(const
0079 noexcept(noexcept(ranges::data(*rng_)))
0080 requires contiguous_range<Rng>)
0081 {
0082 return ranges::data(*rng_);
0083 }
0084 };
0085
0086 #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
0087 template(typename R)(
0088 requires range<R>)
0089 ref_view(R &)
0090 -> ref_view<R>;
0091 #endif
0092
0093 namespace views
0094 {
0095 struct ref_fn
0096 {
0097 template(typename Rng)(
0098 requires range<Rng>)
0099 constexpr ref_view<Rng> operator()(Rng & rng) const noexcept
0100 {
0101 return ref_view<Rng>(rng);
0102 }
0103 template<typename Rng>
0104 void operator()(Rng const && rng) const = delete;
0105 };
0106
0107
0108
0109 RANGES_INLINE_VARIABLE(ref_fn, ref)
0110 }
0111
0112 namespace cpp20
0113 {
0114 template(typename Rng)(
0115 requires std::is_object<Rng>::value)
0116 using ref_view = ranges::ref_view<Rng>;
0117 }
0118 }
0119
0120 #include <range/v3/detail/satisfy_boost_range.hpp>
0121 RANGES_SATISFY_BOOST_RANGE(::ranges::ref_view)
0122
0123 #include <range/v3/detail/epilogue.hpp>
0124
0125 #endif