N
Note Myself
Today I wanted to solve an problem: I need to find out in the code if the
iterator passed is a st::vector<T>::iterator, or
std::vector<T>::reverse_iterator. I spent a lot of time tweaking a template
function which is suppose to sovle the issue -
template<typename T>
bool IsForwardIterator(typename T::iterator)
{ return true; }
template<typename T>
bool IsForwardIterator(typename T::reverse_iterator)
{ return false; }
vector<int> vec;
--> bool bFlag = IsForwardIterator(vec.begin());
--> bFlag = IsForwardIterator(vec.rbegin());
The compiler (VC 7.1) complains that it can not locate the overloaded
function.
What might be wrong. BTW, I solve the problem using typeid function. But it
is irrelevant now.
iterator passed is a st::vector<T>::iterator, or
std::vector<T>::reverse_iterator. I spent a lot of time tweaking a template
function which is suppose to sovle the issue -
template<typename T>
bool IsForwardIterator(typename T::iterator)
{ return true; }
template<typename T>
bool IsForwardIterator(typename T::reverse_iterator)
{ return false; }
vector<int> vec;
--> bool bFlag = IsForwardIterator(vec.begin());
--> bFlag = IsForwardIterator(vec.rbegin());
The compiler (VC 7.1) complains that it can not locate the overloaded
function.
What might be wrong. BTW, I solve the problem using typeid function. But it
is irrelevant now.