I need a function template that takes two iterators, which can be pointers. If two arguments are random_access iterators, I want the return type to be an object
std::iterator<random_access_iterator_tag, ...> type
else a
std::iterator<bidirectional_iterator_tag, ...> .
I also want the code to refuse compilation if the arguments are neither a bidirectional iterator nor a pointer. I cannot have dependencies on third-party libraries, for example. Boost
Could you help me with the signature of this function so that it accepts bidirectional iterators, as well as pointers, but does not say input_iterator, output_iterator, forward_iterators.
One partial solution I can think of is as follows
template<class T> T foo( T iter1, T iter2) { const T tmp1 = reverse_iterator<T>(iter1); const T tmp2 = reverse_iterator<T>(iter2);
The idea is that if it is not bidirectional, the compiler will not allow me to build a reverse_terator from it.
source share