Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Member functions | ||||
Non-member functions | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
Helper classes | ||||
Defined in header <iterator> | ||
template<std::input_or_output_iterator I,std::sentinel_for<I> S> requires(!std::same_as<I, S>&&std::copyable<I>) | (since C++20) | |
std::common_iterator
is an iteratorI
/ sentinelS
adaptor that may represent a non-common range (where the types ofI
andS
differ) as acommon_range
, by containing either an iterator or a sentinel, and defining the appropriate equality comparison operatorsoperator==.
std::common_iterator
can be used as a "bridge" between sequences represented by iterator/sentinel pair and legacy functions that expectcommon_range
-like sequences.
Contents |
Member name | Definition |
var | an object of typestd::variant<I, S> (exposition-only member object*) |
constructs a newcommon_iterator (public member function)[edit] | |
assigns anothercommon_iterator (public member function)[edit] | |
accesses the pointed-to element (public member function)[edit] | |
advances thecommon_iterator (public member function)[edit] |
(C++20) | compares the underlying iterators or sentinels (function template)[edit] |
(C++20) | computes the distance between two iterator adaptors (function template)[edit] |
(C++20) | casts the result of dereferencing the underlying iterator to its associated rvalue reference type (function)[edit] |
(C++20) | swaps the objects pointed to by two underlying iterators (function template)[edit] |
computes the associated difference type of thestd::common_iterator type (class template specialization)[edit] | |
provides uniform interface to the properties of thestd::common_iterator type (class template specialization)[edit] |
#include <algorithm>#include <iostream>#include <iterator>#include <list>#include <string> template<class ForwardIter>void fire(ForwardIter first, ForwardIter last){std::copy(first, last,std::ostream_iterator<std::string>{std::cout," "});} int main(){std::list<std::string> stars{"Pollux","Arcturus","Mira","Aldebaran","Sun"}; using IT= std::common_iterator<std::counted_iterator<std::list<std::string>::iterator>,std::default_sentinel_t>; fire(IT(std::counted_iterator(stars.begin(), stars.size()-1)), IT(std::default_sentinel));}
Output:
Pollux Arcturus Mira Aldebaran
(C++20) | specifies that a range has identical iterator and sentinel types (concept)[edit] |
converts aview into acommon_range (class template)(range adaptor object)[edit] |