A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../utility/../iterator/forward_iterator.html below:

std::forward_iterator - cppreference.com

This concept refines std::input_iterator by requiring that I also model std::incrementable (thereby making it suitable for multi-pass algorithms), and guaranteeing that two iterators to the same range can be compared against each other.

[edit] Iterator concept determination

Definition of this concept is specified via an exposition-only alias template /*ITER_CONCEPT*/.

In order to determine /*ITER_CONCEPT*/<I>, let ITER_TRAITS<I> denote I if the specialization std::iterator_traits<I> is generated from the primary template, or std::iterator_traits<I> otherwise:

[edit] Semantic requirements

I models std::forward_iterator if, and only if I models all the concepts it subsumes, and given objects i and j of type I:

[edit] Notes

Unlike the LegacyForwardIterator requirements, the forward_iterator concept does not require dereference to return a reference.

[edit] Example

A minimum forward iterator.

#include <cstddef>
#include <iterator>
 
class SimpleForwardIterator
{
public:
    using difference_type = std::ptrdiff_t;
    using value_type = int;
 
    SimpleForwardIterator();
    SimpleForwardIterator(const SimpleForwardIterator&);
 
    SimpleForwardIterator& operator=(const SimpleForwardIterator&);
 
    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>);
[edit] See also 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) [edit] specifies that a forward_iterator is a bidirectional iterator, supporting movement backwards
(concept) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4