22#ifndef _ITERTOOLS_RANGE_HPP
23#define _ITERTOOLS_RANGE_HPP
108 [[deprecated(
"range default construction deprecated. Use range::all for full range in slicing operation")]]
range() =
default;
128 if (step_ == 0)
throw std::runtime_error(
"Step-size cannot be zero in construction of integer range");
141 [[nodiscard]]
long first()
const {
return first_; }
144 [[nodiscard]]
long last()
const {
return last_; }
147 [[nodiscard]]
long step()
const {
return step_; }
150 [[nodiscard]]
long size()
const {
return std::max(0l, (last_ + step_ - (step_ > 0 ? 1 : -1) - first_) / step_); }
161 [[nodiscard]]
range operator+(
long shift)
const {
return {first_ + shift, last_ + shift, step_}; }
171 os <<
"range(" << rg.
first() <<
"," << rg.
last() <<
"," << rg.
step() <<
")";
234 return (other.pos == this->pos) || (other.atEnd() && this->
atEnd());
304 template <
typename... Is,
typename EnableIf = std::enable_if_t<(std::is_integral_v<Is> and ...),
int>> [[nodiscard]]
auto product_range(Is... is) {
311 template <
typename T,
size_t... Is> [[gnu::always_inline]]
auto product_range_impl(T
const &idxs, std::index_sequence<Is...>) {
344 template <
typename... Is,
typename EnableIf = std::enable_if_t<(std::is_integral_v<Is> and ...),
int>>
346 return detail::product_range_impl(idx_tpl, std::make_index_sequence<
sizeof...(Is)>{});
377 template <
typename I,
size_t N,
typename EnableIf = std::enable_if_t<std::is_
integral_v<I>,
int>>
379 return detail::product_range_impl(idx_arr, std::make_index_sequence<N>{});
402 template <
typename F>
void foreach (
range const &rg, F && f) {
404 for (; i < last; i += step) std::forward<F>(f)(i);
auto product_range(Is... is)
Create a cartesian product range of integer ranges from given integers.
itertools::multiplied< Rs... > product(Rs &&...rgs)
Lazy-multiply a given number of ranges by forming their cartesian product.
Provides a range adapting function for multiplying a given number of ranges/views (cartesian product)...