std::ranges...de_view::end(3)

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

πŸ’… std::ranges::stride_view::end πŸ’…

okay so this is a page from the C++ Standard Library manual, section 3, and it's all about std::ranges::stride_view::end. she's the one who tells you where the party stops. πŸŽ€


✨ SYNOPSIS ✨

constexpr auto end() requires (!__simple_view<V>);         (1) (since C++23)
constexpr auto end() const requires ranges::range<const V> (2) (since C++23)

So there's two overloads bestie, both constexpr, both landing in C++23. number (1) is the non-const one and it's only available when !__simple_view<V> is true; number (2) is the const one and it needs ranges::range<const V> to hold. 🫢


🌸 DESCRIPTION 🌸

She returns an iterator or a sentinel representing the end of the stride_view. literally her whole job. πŸ’–

okay so let's define the players β€” base_ and stride_ are the underlying data members:

  • overload (1) β†’ Const is defined as using Const = false; and Base as using Base = V;
  • overload (2) β†’ Const is defined as using Const = true; and Base as using Base = const V;

and it's equivalent to this, no cap:

if constexpr (ranges::common_range<Base> &&
              ranges::sized_range<Base> &&
              ranges::forward_range<Base>)
{
    auto missing = (stride_ - ranges::distance(base_) % stride_) % stride_;
    return iterator<Const>(this, ranges::end(base_), missing);
}
else if constexpr (ranges::common_range<Base> &&
                   !ranges::bidirectional_range<Base>)
{
    return iterator<Const>(this, ranges::end(base_));
}
else
{
    return std::default_sentinel;
}

three branches, three vibes. she checks the concepts and picks the right one, periodt. πŸ’…


πŸ¦‹ PARAMETERS πŸ¦‹

  • (none) β€” yeah bestie, she takes zero arguments. the way that she just knows 😭

πŸ’œ RETURN VALUE πŸ’œ

An iterator to the element following the last element, if the underlying view V models common_range. Otherwise, it's the std::default_sentinel, and that sentinel compares equal to the end iterator. both are valid endings, iykyk. 🌈


πŸ”₯ NOTES πŸ”₯

stride_view<V> models common_range whenever the underlying view V does. so like, the commonness trickles down. 🧚


πŸ“ EXAMPLE πŸ“

This section is incomplete πŸ™ˆ Reason: no example 😭

not me showing up with zero examples, iconic honestly. Category: * Todo no example πŸ’€


πŸ‘‘ SEE ALSO πŸ‘‘

  • begin β€” returns an iterator to the beginning (C++23) (public member function) ✨
  • ranges::end β€” returns a sentinel indicating the end of a range (C++20) (customization point object) ⭐

okay that's the whole page slay πŸ’– the source is http://cppreference.com, dated 2024.06.10, from the std::ranges...de_view::end(3) page β€” catch you in the group chat bestie, mwah πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from