std::experi...ranges::next(3)
π std::experimental::ranges::next
okay bestie, welcome to the C++ Standard Library corner of the multiverse β¨ this one lives in the std::experimental::ranges namespace, so it's giving "ranges TS era" β very vintage, very cppreference dot com, 2024.06.10 vibes π
β¨ NAME β¨
std::experimental::ranges::next β literally just std::experimental::ranges::next, no notes, that's the whole name, slay π
πΈ SYNOPSIS πΈ
okay so first things first, it's Defined in header <experimental/ranges/iterator> β that's where you gotta look, don't come for me if you can't find it π¦
Then there's this whole namespace situation:
namespace {
(ranges
constexpr /* unspecified */ next = /* unspecified */;
(customization point
object)
}
yeah it's a customization point object, note the constexpr /* unspecified */ β the standard is being mysterious on purpose, it's giving mystery, it's giving main character energy β¨ (and yes, it's marked (ranges TS) up in the corner, iykyk)
π Call signature π
here's the lineup, four whole overloads, no cap:
template< Iterator I > (1)
constexpr I next( I i );
template< Iterator I > (2)
constexpr I next( I i, ranges::difference_type_t<I> n );
template< Iterator I, Sentinel<I> S > (3)
constexpr I next( I i, S bound );
template< Iterator I, Sentinel<I> S >
constexpr I next( I i, ranges::difference_type_t<I> n, S (4)
bound );
so what does it do?? it advances the iterator i n times, or until bound is reached β whichever comes first, bestie, whichever comes FIRST π β and then it returns the advanced iterator. iconic behavior honestly.
- (1) β equivalent to
++i; return i;. that's it. one hop. periodt. - (2) β equivalent to
ranges::advance(i, n); return i;. scoot itntimes, hand it back π«Ά - (3) β equivalent to
ranges::advance(i, bound); return i;. no count, just vibes untilboundshows up π - (4) β equivalent to
ranges::advance(i, n, bound); return i;.nANDbound, and whoever wins, wins π₯
β RETURN VALUE β
The advanced iterator. that's it. that's the whole thing. give it back to me π
π¦ NOTES π¦
okay this part is lowkey important so listen up π
even though omitting n for overload (2) behaves as if n is 1, omitting n for overload (4) effectively behaves as if n is infinity (always advance to bound).
so like. same "missing argument" energy, WILDLY different result. one is a single step, the other runs all the way home πββοΈπ¨ do not confuse them fr fr, that's a trap and you deserve better π
π EXAMPLE π
This section is incomplete Reason: no example
not me showing up with zero examples π the cppreference girlies literally left it blank. it's giving "we'll finish this later" and later never came π
π SEE ALSO π
next(C++11) β increment an iterator (function template)advanceβ advances an iterator by given distance (function template)prevβ decrement an iterator (function template)- β returns the distance between an iterator and a sentinel, or between the beginning and the end of a range (function template)
(yeah that last one has no name attached on this page, bestie β I'm not gonna invent one, I'm respectful like that π«Ά)
π CATEGORY π
* Todo no example
the todo list said what it said and honestly? she's valid for it π
Sign-off: that's the tea, bestie π this little number lives over at http://cppreference.com, and this particular snapshot is stamped 2024.06.10 π go forth, advance your iterators, and remember: no cap, always check your bounds β¨π¦πΈ
π¦ 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