operator+(std::counted_iterator) - cppreference.com (original) (raw)
Returns an iterator adaptor which is advanced by n. The behavior is undefined if n is greater than the length recorded within x (i.e. if x + n result in undefined behavior).
This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::counted_iterator is an associated class of the arguments.
[edit] Parameters
n | - | the number of positions to increment the iterator |
---|---|---|
x | - | the iterator adaptor to increment |
[edit] Return value
An iterator adaptor equal to x + n.
[edit] Example
#include #include #include #include int main() { std::vector v{0, 1, 2, 3, 4, 5}; std::counted_iterator<std::vector::iterator> p{v.begin() + 1, 4}; std::cout << "*p:" << *p << ", count:" << p.count() << '\n'; std::counted_iterator<std::vector::iterator> q{2 + p}; std::cout << "*q:" << *q << ", count:" << q.count() << '\n'; std::list l{6, 7, 8, 9}; std::counted_iterator<std::list::iterator> r{l.begin(), 3}; std::cout << "*r:" << *r << ", count:" << r.count() << '\n'; // auto s{2 + r}; // error: the underlying iterator does // not model std::random_access_iterator }
Output:
*p:1, count:4 *q:3, count:2 *r:6, count:3