13 #ifndef RANGES_V3_VIEW_CACHE1_HPP
14 #define RANGES_V3_VIEW_CACHE1_HPP
28 #include <range/v3/detail/prologue.hpp>
34 template<
typename Rng>
38 CPP_assert(view_<Rng>);
39 CPP_assert(input_range<Rng>);
40 CPP_assert(constructible_from<range_value_t<Rng>, range_reference_t<Rng>>);
44 detail::non_propagating_cache<range_value_t<Rng>> cache_;
47 auto update_(range_reference_t<Rng> && val)
49 requires assignable_from<range_value_t<Rng> &, range_reference_t<Rng>>)
52 cache_.emplace(
static_cast<range_reference_t<Rng> &&
>(val));
54 *cache_ =
static_cast<range_reference_t<Rng> &&
>(val);
57 auto update_(range_reference_t<Rng> && val)
59 requires (!assignable_from<range_value_t<Rng> &, range_reference_t<Rng>>))
61 cache_.emplace(
static_cast<range_reference_t<Rng> &&
>(val));
70 sentinel_t<Rng> last_;
74 constexpr
explicit sentinel(sentinel_t<Rng> last)
75 : last_(std::move(last))
86 using value_type = range_value_t<Rng>;
87 using single_pass = std::true_type;
88 using difference_type = range_difference_t<Rng>;
94 , current_(std::move(current))
96 range_value_t<Rng> && read()
const
100 parent_->update_(*current_);
101 parent_->dirty_ =
false;
103 return std::move(*parent_->cache_);
108 parent_->dirty_ =
true;
110 bool equal(cursor
const & that)
const
112 return current_ == that.current_;
114 bool equal(sentinel
const & that)
const
116 return current_ == that.last_;
119 auto distance_to(cursor
const & that)
const
120 -> CPP_ret(difference_type)(
123 return that.current_ - current_;
126 auto distance_to(sentinel
const & that)
const
127 -> CPP_ret(difference_type)(
130 return that.last_ - current_;
134 cursor begin_cursor()
137 return cursor{
this, ranges::begin(rng_)};
140 cursor end_cursor_impl(std::true_type)
142 return cursor{
this, ranges::end(rng_)};
144 sentinel end_cursor_impl(std::false_type)
146 return sentinel{ranges::end(rng_)};
150 return end_cursor_impl(
meta::bool_<(
bool)common_range<Rng>>{});
156 : rng_{std::move(rng)}
159 constexpr
auto CPP_fun(size)()(
160 requires sized_range<Rng>)
166 #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
167 template<
typename Rng>
181 template(
typename Rng)(
182 requires viewable_range<Rng> AND input_range<Rng> AND
183 constructible_from<range_value_t<Rng>, range_reference_t<Rng>>)
198 #include <range/v3/detail/epilogue.hpp>
199 #include <range/v3/detail/satisfy_boost_range.hpp>
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector >>, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition: conversion.hpp:399
std::integral_constant< bool, B > bool_
An integral constant wrapper for bool.
Definition: meta.hpp:168
meta::size_t< L::size()> size
An integral constant wrapper that is the size of the meta::list L.
Definition: meta.hpp:1696
Definition: cache1.hpp:36
A utility for constructing a view from a (derived) type that implements begin and end cursors.
Definition: facade.hpp:66
Definition: cache1.hpp:175