std::ranges...brange::next(3)
π std::ranges...brange::next(3) π
okay bestie, this is the C++ Standard Libary manual page for std::ranges...brange::next(3) β yes, thatβs the manual name, folded in right here near the top like a little name tag, mwah π. Weβre talking about std::ranges::subrange::next, and itβs lowkey iconic.
πΈ NAME πΈ
std::ranges::subrange::nextβstd::ranges::subrange::next
β¨ Synopsis β¨
okay so there are two overloads, both (since C++20), both [[nodiscard]] constexpr, and both return a subrange. The default is literally n = 1 in both. Overload (1) is const& and requires std::forward_iterator<I>. Overload (2) is &&. Here they are in all their main-character glory:
[[nodiscard]] constexpr subrange next(std::iter_difference_t<I> n = 1) const&
requires std::forward_iterator<I>;
(1) (since C++20)
[[nodiscard]] constexpr subrange next(std::iter_difference_t<I> n = 1) &&;
(2) (since C++20)
- Overload
(1)β Obtains asubrangewhose iterator is incremented bymin(n, size())times or decremented by-ntimes respect to that of*this, whenn >= 0orn < 0respectively. Equivalent toauto tmp = *this; tmp.advance(n); return tmp;. - Overload
(2)β Increments the stored iterator bymin(n, size())times or decremented it by-ntimes, whenn >= 0orn < 0respectively, and then move-constructs the result from*this. Equivalent toadvance(n); return std::move(*this);.
The behavior is undefined if: -Idoes not modelbidirectional_iteratorandn < 0, or - the stored iterator is decremented after becoming a non-decrementable value.
bestie, that undefined-behavior bullet is not the vibe check you want to fail π periodt.
π Return value π
A subrange whose iterator is incremented by min(n, size()) times or decremented by -n times respect to the original value of that of *this, when n >= 0 or n < 0 respectively. slay π«Ά
π₯ Complexity π₯
Generally min(n, size()) increments or -n decrements on the iterator, when n >= 0 or n < 0 respectively.
Constant if I models random_access_iterator, and either n < 0 or std::sized_sentinel_for<S, I> is modeled. thatβs the whole tea ββ¨
π¦ Notes π¦
A call to (2) may leave *this in a valid but unspecified state, depending on the behavior of the move constructor of I and S. ngl, βvalid but unspecifiedβ is giving mystery box energy ππ.
π Example π
This section is incomplete. Reason: no example.
literally no example, bestie β the manual said βnot me leaving this blankβ π.
π See also π
prev(C++20)β obtains a copy of thesubrangewith its iterator decremented by a given distance (public member function)advance(C++20)β advances the iterator by given distance (public member function)next(C++11)β increment an iterator (function template)ranges::next(C++20)β increment an iterator by a given distance or to a bound (niebloid)
π§ Category π§
* Todo no example
mwah π β this came from http://cppreference.com, version/date 2024.06.10, page std::ranges...brange::next(3). bye bestie, go slay those subranges! π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms