C++ Input Iterator -
i'm reading c++ standard (section input iterator) , i'm having hard time visualize text in bold:
note: input iterators, == b not imply ++a == ++b. (equality not guarantee substitution property or referential transparency.) algorithms on input iterators should never attempt pass through same iterator twice. should single pass algorithms.
i understand input iterators single pass, can't seem visualize in c++ code. can please show me in example on how make iterator become single pass?
suppose want read integers standard input. 1 way using
#include <iterator> #include <iostream> #include <vector> using namespace std; const vector<int> v{istream_iterator<int>{cin}, istream_iterator<int>{}}; this read integers v (see istream_iterator).
in case, makes lot of sense iterators single pass, since range created on fly, user types in things, , each element consumed , disappeared. can't reiterate range.
other that, not sure mean
how make iterator become single pass?
if mean "how signify iterator class you're writing has restriction?", set
iterator_categoryinput_iterator_tagstruct my_iterator { using iterator_category = input_iterator_tag; };if want query (at compile time) whether iterator class has restriction, use
iterator_traits.
Comments
Post a Comment