14 #ifndef RANGES_V3_VIEW_ZIP_WITH_HPP
15 #define RANGES_V3_VIEW_ZIP_WITH_HPP
19 #include <type_traits>
35 #include <range/v3/utility/static_const.hpp>
41 #include <range/v3/detail/prologue.hpp>
50 template<
typename T,
typename U>
51 bool operator()(T
const & t, U
const & u)
const
53 return static_cast<bool>(t == u);
61 void operator()(T & t)
const
71 void operator()(T & t)
const
80 template(
typename I,
typename Diff)(
81 requires input_or_output_iterator<I> AND integer_like_<Diff>)
82 void operator()(I & i, Diff n)
const
84 advance(i,
static_cast<iter_difference_t<I>
>(n));
92 constexpr
auto operator()(T
const & t, T
const & u)
const -> decltype(u - t)
101 template<
typename T,
typename U>
102 constexpr
auto operator()(T
const & t, U
const & u)
const
103 -> decltype(
true ? t : u)
105 return u < t ? u : t;
112 template<
typename T,
typename U>
113 constexpr
auto operator()(T
const & t, U
const & u)
const
114 -> decltype(
true ? u : t)
116 return u < t ? t : u;
121 template<
typename State,
typename Value>
122 using zip_cardinality = std::integral_constant<
124 State::value >= 0 && Value::value >= 0
125 ?
min_(State::value, Value::value)
126 : State::value >=0 && Value::value == infinite
128 : State::value == infinite && Value::value >= 0
130 : State::value == finite || Value::value == finite
132 : State::value == unknown || Value::value == unknown
143 template(
typename Fun,
typename... Rngs)(
144 concept (zippable_with_)(Fun, Rngs...),
145 invocable<Fun&, iterator_t<Rngs>...> AND
146 invocable<Fun&, copy_tag, iterator_t<Rngs>...> AND
147 invocable<Fun&, move_tag, iterator_t<Rngs>...>
151 template<
typename Fun,
typename ...Rngs>
153 and_v<input_range<Rngs>...> &&
154 copy_constructible<Fun> &&
155 CPP_concept_ref(views::zippable_with_, Fun, Rngs...);
161 template<
typename Fun,
typename... Rngs>
164 meta::fold<meta::list<range_cardinality<Rngs>...>,
165 std::integral_constant<cardinality, cardinality::infinite>,
166 meta::quote<detail::zip_cardinality>>::value>
169 CPP_assert(
sizeof...(Rngs) != 0);
172 semiregular_box_t<Fun> fun_;
173 std::tuple<Rngs...> rngs_;
174 using difference_type_ = common_type_t<range_difference_t<Rngs>...>;
183 friend struct cursor<Const>;
184 friend struct sentinel<!Const>;
185 std::tuple<sentinel_t<meta::const_if_c<Const, Rngs>>...> ends_;
188 sentinel() =
default;
189 sentinel(detail::ignore_t,
190 std::tuple<sentinel_t<meta::const_if_c<Const, Rngs>>...> ends)
191 : ends_(std::move(ends))
193 template(
bool Other)(
194 requires Const AND CPP_NOT(Other))
195 sentinel(sentinel<Other> that)
196 : ends_(std::move(that.ends_))
204 friend struct cursor<!Const>;
205 using fun_ref_ = semiregular_box_ref_or_val_t<Fun, Const>;
207 std::tuple<iterator_t<meta::const_if_c<Const, Rngs>>...> its_;
210 using difference_type =
211 common_type_t<range_difference_t<meta::const_if_c<Const, Rngs>>...>;
213 bool)single_pass_iterator_<
iterator_t<meta::const_if_c<Const, Rngs>>>...>;
214 using value_type = detail::decay_t<invoke_result_t<
219 std::tuple<
iterator_t<meta::const_if_c<Const, Rngs>>...> its)
220 : fun_(std::move(fun))
221 , its_(std::move(its))
223 template(
bool Other)(
224 requires Const AND CPP_NOT(Other))
225 cursor(cursor<Other> that)
226 : fun_(std::move(that.fun_))
227 , its_(std::move(that.its_))
230 auto CPP_auto_fun(read)()(
const)
232 return tuple_apply(fun_, its_)
240 auto equal(cursor
const & that)
const
243 sentinel_for<iterator_t<meta::const_if_c<Const, Rngs>>,
251 [](
bool a,
bool b) { return a || b; });
253 bool equal(sentinel<Const>
const & s)
const
260 [](
bool a,
bool b) { return a || b; });
265 requires and_v<bidirectional_range<meta::const_if_c<Const, Rngs>>...>)
270 auto advance(difference_type n)
272 requires and_v<random_access_range<meta::const_if_c<Const, Rngs>>...>)
274 tuple_for_each(its_,
bind_back(detail::advance_, n));
277 auto distance_to(cursor
const & that)
const
278 -> CPP_ret(difference_type)(
280 sized_sentinel_for<iterator_t<meta::const_if_c<Const, Rngs>>,
285 if(0 < std::get<0>(that.its_) - std::get<0>(its_))
287 tuple_transform(its_, that.its_, detail::distance_to),
288 (std::numeric_limits<difference_type>::max)(),
292 tuple_transform(its_, that.its_, detail::distance_to),
293 (std::numeric_limits<difference_type>::min)(),
303 auto move()
const noexcept(noexcept(std::declval<cursor const &>().move_(
305 -> decltype(std::declval<cursor const &>().move_(
314 meta::if_c<concepts::and_v<(bool)common_range<Rngs>...,
315 !(
bool)single_pass_iterator_<iterator_t<Rngs>>...>,
316 cursor<Const>, sentinel<Const>>;
318 cursor<false> begin_cursor()
320 return {fun_, tuple_transform(rngs_, ranges::begin)};
322 end_cursor_t<false> end_cursor()
324 return {fun_, tuple_transform(rngs_, ranges::end)};
326 template(
bool Const =
true)(
327 requires Const AND and_v<range<Rngs const>...> AND
329 cursor<Const> begin_cursor()
const
331 return {fun_, tuple_transform(rngs_, ranges::begin)};
333 template(
bool Const =
true)(
334 requires Const AND and_v<range<Rngs const>...> AND
336 end_cursor_t<Const> end_cursor()
const
338 return {fun_, tuple_transform(rngs_, ranges::end)};
345 , rngs_{std::move(rngs)...}
348 : fun_(std::move(fun))
349 , rngs_{std::move(rngs)...}
352 constexpr
auto CPP_fun(
size)()(
const
353 requires and_v<sized_range<Rngs const>...>)
355 using size_type = common_type_t<range_size_t<Rngs const>...>;
359 : tuple_foldl(tuple_transform(rngs_,
360 [](
auto && r) -> size_type {
363 (std::numeric_limits<size_type>::max)(),
368 template<
typename Fun,
typename... Rngs>
371 CPP_assert(
sizeof...(Rngs) != 0);
383 #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
384 template(
typename Fun,
typename... Rng)(
385 requires copy_constructible<Fun>)
394 template(
typename... Rngs,
typename Fun)(
395 requires and_v<viewable_range<Rngs>...> AND
396 zippable_with<Fun, Rngs...> AND (
sizeof...(Rngs) != 0))
398 operator()(Fun fun, Rngs &&... rngs)
const
401 std::move(fun), all(
static_cast<Rngs &&
>(rngs))...};
404 template(
typename Fun)(
405 requires zippable_with<Fun>)
407 operator()(Fun)
const noexcept
419 template(
typename... Rngs,
typename Fun)(
420 requires and_v<viewable_range<Rngs>...> AND
421 and_v<input_range<Rngs>...> AND copy_constructible<Fun> AND
422 invocable<Fun &, range_reference_t<Rngs>...> AND
423 (
sizeof...(Rngs) != 0))
424 zip_with_view<Fun, all_t<Rngs>...>
operator()(Fun fun, Rngs &&... rngs)
const
427 std::move(fun), all(
static_cast<Rngs &&
>(rngs))...};
430 template(
typename Fun)(
431 requires copy_constructible<Fun> AND invocable<Fun &>)
433 operator()(Fun)
const noexcept
446 #include <range/v3/detail/epilogue.hpp>
448 #include <range/v3/detail/satisfy_boost_range.hpp>
CPP_concept invocable
\concept invocable
Definition: concepts.hpp:48
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
_t< detail::make_indices_< N, index_sequence< 0 >, detail::strategy_(1, N)> > make_index_sequence
Generate index_sequence containing integer constants [0,1,2,...,N-1].
Definition: meta.hpp:473
std::integral_constant< std::size_t, N > size_t
An integral constant wrapper for std::size_t.
Definition: meta.hpp:163
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
defer< bind_back, Fn, Ts... > bind_back
Definition: meta.hpp:994
meta::size_t< L::size()> size
An integral constant wrapper that is the size of the meta::list L.
Definition: meta.hpp:1696
fold< pop_front< list< Ts... > >, front< list< Ts... > >, quote< detail::min_ > > min_
An integral constant wrapper around the minimum of Ts::type::value...
Definition: meta.hpp:2197
bool_< T::type::value==U::type::value > equal_to
A Boolean integral constant wrapper around the result of comparing T::type::value and U::type::value ...
Definition: meta.hpp:237
fold< pop_front< list< Ts... > >, front< list< Ts... > >, quote< detail::max_ > > max_
An integral constant wrapper around the maximum of Ts::type::value...
Definition: meta.hpp:2205
CPP_concept zippable_with
\concept zippable_with
Definition: zip_with.hpp:152
Definition: range_fwd.hpp:492
Definition: zip_with.hpp:167
Definition: range_fwd.hpp:494
Definition: traits.hpp:128
A utility for constructing a view from a (derived) type that implements begin and end cursors.
Definition: facade.hpp:66
Definition: zip_with.hpp:393
Definition: zip_with.hpp:418
Definition: zip_with.hpp:370