Lambda said:
Hi, All,
Why the search() function use Forward Iterator?
I think Input Iterator is enough, I need read only.
In such kind of situations, how should I choose iterator type?
Please refer to clause [24.1.1/3]:
[Note: For input iterators, a == b does not imply ++a == ++b. (Equality
does not guarantee the substitution property or referential transparency.)
Algorithms on input iterators should never attempt to pass through the
same iterator twice. They should be single pass algorithms. Value type T
is not required to be an Assignable type (23.1). These algorithms can be
used with istreams as the source of the input data through the
istream_iterator class. ]
Note that std::search might want to back-track. That is why the standard
required forward iterators not only on the pattern.
Best
Kai-Uwe Bux