std::ranges...ator::next,(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

NAME πŸ’–

  • std::ranges::cartesian_product_view::iterator::next, -
  • std::ranges::cartesian_product_view::iterator::next,

okay bestie, welcome to the std::ranges...ator::next,(3) page from the C++ Standard Libary manual πŸ’… this one is all about the exposition-only helpers hanging out inside std::ranges::cartesian_product_view::iterator, and yes we are getting into the recursive iterator sauce ✨


Synopsis πŸ¦‹

the synopsis opens with this absolute unit of a signature:

std::ranges::cartesian_product_view<First, Vs...>::iterator<Const>::distance_from

/*next*/ β€” exposition only* πŸ‘‘

template< std::size_t N = sizeof...(Vs) >  (since C++23)
constexpr void /*next*/();                 (exposition only*)

if you call it with the default template parameter, it recursively generates the next element (the tuple of iterators) in cartesian_product_view 🫢

let current_ denote the underlying tuple of iterators. it's equivalent to:

auto& it = std::get<N>(current_);
++it;
if constexpr (N > 0)
{
    if (it == ranges::end(std::get<N>(parent_->bases_)))
    {
        it = ranges::begin(std::get<N>(parent_->bases_));
        next<N - 1>();
    }
}

used in the following non-static member functions:

  • ranges::cartesian_product_view::operator+

/*prev*/ β€” exposition only* 🌈

template< std::size_t N = sizeof...(Vs) >  (since C++23)
constexpr void /*prev*/();                 (exposition only*)

if you call it with the default template parameter, it recursively generates the previous element (the tuple of iterators) in cartesian_product_view 🧚

let current_ denote the underlying tuple of iterators. it's equivalent to:

auto& it = std::get<N>(current_);
if constexpr (N > 0)
{
    if (it == ranges::begin(std::get<N>(parent_->bases_)))
    {
        it = /*cartesian-common-arg-
               end*/(std::get<N>(parent_->bases_));
        prev<N - 1>();
    }
}
--it;

used in the following non-static member functions:

  • ranges::cartesian_product_view::operator-

/*distance_from*/ β€” exposition only* πŸŽ€

template< class Tuple >
                                                          (since C++23)
constexpr difference_type                       (exposition only*)

    /*distance-from*/( const Tuple& t ) const;

returns the "distance" (i.e., number of "hops") between two iterators πŸ¦‹

let:

  • parent_ be the underlying pointer to cartesian_product_view
  • /*scaled-size*/(N) be:
    • the product of static_cast<difference_type>(ranges::size(std::get<N>(parent_->bases_))) and /*scaled-size*/(N + 1) if N ≀ sizeof...(Vs), otherwise
    • static_cast<difference_type>(1);
  • /*scaled-distance*/(N) be the product of static_cast<difference_type>(std::get<N>(current_) - std::get<N>(t)) and /*scaled-size*/(N + 1);
  • /*scaled-sum*/ be the sum of /*scaled-distance*/(N) for every integer 0 ≀ N ≀ sizeof...(Vs).

returns: /*scaled-sum*/ ⭐

the behavior is undefined if /*scaled-sum*/ cannot be represented by difference_type β€” that's UB, bestie, not a cute vibe πŸ˜­πŸ’€

used in the following functions:

  • operator-(const /*iterator*/&, const /*iterator*/&)
  • operator-(const /*iterator*/&, std::default_sentinel_t)

Parameters 🌸

  • t β€” a tuple of iterators to find the distance to

mwah πŸ’‹ this little icon comes from http://cppreference.com, dated 2024.06.10, with the footer name std::ranges...ator::next,(3) β€” periodt, we ate and left no crumbs πŸ‘‘πŸ’œ

πŸ“¦ where this page comes from