Difference between revisions of "cpp/iterator/input or output iterator"
From cppreference.com
m (in-house formatting.) |
(Links to the definition of “referenceable type”.) |
||
Line 12: | Line 12: | ||
The {{tt|input_or_output_iterator}} concept forms the basis of the iterator concept taxonomy; every iterator type satisfies the {{tt|input_or_output_iterator}} requirements. | The {{tt|input_or_output_iterator}} concept forms the basis of the iterator concept taxonomy; every iterator type satisfies the {{tt|input_or_output_iterator}} requirements. | ||
− | The exposition-only concept {{c|/*can-reference*/}} is satisfied if and only if the type is | + | The exposition-only concept {{c|/*can-reference*/}} is satisfied if and only if the type is [[cpp/meta#Definitions|referenceable]]. |
{{todo|Is *i required to be equality-preserving?}} | {{todo|Is *i required to be equality-preserving?}} | ||
Line 35: | Line 35: | ||
{ | { | ||
using difference_type = std::ptrdiff_t; | using difference_type = std::ptrdiff_t; | ||
− | + | ||
int operator*(); | int operator*(); | ||
− | + | ||
SimpleIterator& operator++(); | SimpleIterator& operator++(); | ||
void operator++(int) { ++*this; } | void operator++(int) { ++*this; } |
Latest revision as of 23:27, 4 September 2024
Defined in header <iterator>
|
||
template< class I > concept input_or_output_iterator = |
(since C++20) | |
The input_or_output_iterator
concept forms the basis of the iterator concept taxonomy; every iterator type satisfies the input_or_output_iterator
requirements.
The exposition-only concept /*can-reference*/ is satisfied if and only if the type is referenceable.
This section is incomplete Reason: Is *i required to be equality-preserving? |
[edit] Notes
input_or_output_iterator
itself only specifies operations for dereferencing and incrementing an iterator. Most algorithms will require additional operations, for example:
- comparing iterators with sentinels (see
sentinel_for
); - reading values from an iterator (see
indirectly_readable
andinput_iterator
); - writing values to an iterator (see
indirectly_writable
andoutput_iterator
); - a richer set of iterator movements (see
forward_iterator
,bidirectional_iterator
,random_access_iterator
).
Unlike the LegacyIterator requirements, the input_or_output_iterator
concept does not require copyability.
[edit] Example
A minimum iterator.
#include <cstddef> #include <iterator> struct SimpleIterator { using difference_type = std::ptrdiff_t; int operator*(); SimpleIterator& operator++(); void operator++(int) { ++*this; } }; static_assert(std::input_or_output_iterator<SimpleIterator>);