std::forward_iterator(3)
π std::forward_iterator β a page from the C++ Standard Libary manual, section 3
okay bestie, so this is the manual page for std::forward_iterator, straight out of the C++ Standard Libary manual (yes, section 3, she's official π). Sit down, get a lil snack π, and let's get into it.
β¨ NAME β¨
std::forward_iterator β literally just std::forward_iterator, no notes π
π¦ SYNOPSIS π¦
So this concept lives in the header <iterator>, and here's exactly what she looks like:
template< class I >
concept forward_iterator =
std::input_iterator<I> &&
std::derived_from</*ITER_CONCEPT*/<I>, std::forward_iterator_tag> &&
std::incrementable<I> &&
std::sentinel_for<I, I>;
(since C++20) β she's a modern girlie, no cap β¨
πΈ DESCRIPTION πΈ
The way this concept just refines std::input_iterator⦠obsessed. Here's the tea:
- she requires that
Ialso modelsstd::incrementableβ which lowkey makes her suitable for multi-pass algorithms π₯ - and she guarantees that two iterators to the same range can be compared against each other π«Ά
Like, that's it, that's the whole vibe. Iconic behaviour, truly. π
π NOTES π
okay this part matters, pay attention bestie π β unlike the LegacyForwardIterator requirements, the forward_iterator concept does not require dereference to return a reference. Not me being surprised by thatβ¦ π but fr fr, that's the actual rule.
π§ EXAMPLE π§
here's a minimum forward iterator, and honestly she ate:
#include <cstddef>
#include <iterator>
struct SimpleForwardIterator
{
using difference_type = std::ptrdiff_t;
using value_type = int;
int operator*() const;
SimpleForwardIterator& operator++();
SimpleForwardIterator operator++(int)
{
auto tmp = *this;
++*this;
return tmp;
}
bool operator==(const SimpleForwardIterator&) const;
};
static_assert(std::forward_iterator<SimpleForwardIterator>);
the static_assert at the end? that's the vibe check, and she passed π
β¨
π SEE ALSO π
input_iterator(C++20) β specifies that a type is an input iterator, that is, its referenced values can be read and it can be both pre- and post-incremented (concept)bidirectional_iterator(C++20) β specifies that aforward_iteratoris a bidirectional iterator, supporting movement backwards (concept)
iykyk, the iterator family tree is giving main character energy π
anyway that's the page!! source is http://cppreference.com, version 2024.06.10, and the date on the cover is 2024.06.10 too (she's stamped and dated, periodt). go forth and iterate forward bestie πππ¦
π¦ 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