I have a function that should list an iterator several times, but according to MSDN : "Once you enlarge any copy of the input iterator, none of the other copies can be boldly compared, dereferenced, or enlarged after that."
So, in order to simplify the task, instead of creating a separate implementation for non-forward-iterators that copies the data and lists the copy, I want to limit my method to only use forwarding iterators and statically reject input iterators.
Now I have something like:
template<typename It, typename TCallback > bool EnumerateTwice(const It &begin, const It &end, TCallback callback) { for (It it = begin; it != end; ++it) if (!callback(*it)) return false; for (It it = begin; it != end; ++it) if (!callback(*it)) return false; return true; }
but nothing limits It as a forward iterator.
How to place this restriction on a template function? (C ++ 03)
source share