| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Non-member functions | ||||
(C++20) | ||||
operator- (C++20) | ||||
(C++20) | ||||
(C++20) | ||||
| Helper classes | ||||
template<std::sized_sentinel_for<I> I2,std::sized_sentinel_for<I> S2> requiresstd::sized_sentinel_for<S, I2> | (since C++20) | |
Computes the distance between two iterator adaptors. Two sentinels are considered equal.
Letvar denote the underlyingstd::variant member object instd::common_iterator, the behavior is undefined if eitherx ory is invalid, i.e.x.var.valueless_by_exception()|| y.var.valueless_by_exception() istrue.
This function template is not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup when std::common_iterator<I> is an associated class of the arguments.
Contents |
| x, y | - | iterator adaptors to compute the difference of |
S object andy.var holds anS2 object, i.e. both of them hold a sentinel.alt_x andalt_y are the alternatives held byx.var andy.var, respectively (either two iterators or one iterator and one sentinel).#include <algorithm>#include <iostream>#include <iterator> int main(){int a[]{0,1,2,3,4,5}; using CI=std::common_iterator<std::counted_iterator<int*>,std::default_sentinel_t>; CI i1{std::counted_iterator{a+1,2}}; CI i2{std::counted_iterator{a,3}}; CI s1{std::default_sentinel}; CI s2{std::default_sentinel}; std::cout<<(s2- s1)<<' '<<(i2- i1)<<' '<<(i1- s1)<<'\n';}
Output:
0 -1 -2
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3574 | C++20 | variant was fully constexpr (P2231R1) butcommon_iterator was not | also made constexpr |
advances thecommon_iterator(public member function)[edit] |