I have a template class with a nested template custom iterator (specialized into const/non-const iterators) like this :
template <typename T>
struct A
{
template <typename U>
struct AIterator
{
//...
};
typename AIterator<T*> iterator;
typename AIterator<const T*> const_iterator;
};
template <typename T>
bool operator==(const typename A<T>::iterator& lhs,
const typename A<T>::iterator& rhs,)
{
//...
}
template <typename T>
bool operator!=(const typename A<T>::iterator& lhs,
const typename A<T>::iterator& rhs,)
{
//...
}
//idem for const_iterator...
But clang can't infer the template parameter :
snake_test.cpp:17:68: error: invalid operands to binary expression ('wavelet::Snake<float>::const_iterator' (aka 'Iterator<const float *>') and 'const_iterator' (aka 'Iterator<const float *>'))
for (wavelet::Snake<float>::const_iterator it = snake.begin(); it != snake.end(); it++)
~~ ^ ~~~~~~~~~~~
./snake.hpp:150:6: note: candidate template ignored: couldn't infer template argument 'T'
bool operator!=(const typename Snake<T>::iterator& lhs,
^
./snake.hpp:164:6: note: candidate template ignored: couldn't infer template argument 'T'
bool operator!=(const typename Snake<T>::const_iterator& lhs,
^
1 error generated.
What am I doing wrong ? How to properly implement custom iterators for template classes ?
lhs&should be&lhs, etc. The trailing commas after therhsarguments aren't helping much either. - WhozCraigoperator==andoperator!=inside ofA? - More AxesA<T>::iterator,Tcannot be deduced. - dypstruct BigInt { BigInt(int); }; BigInt b; 42 == b) and is "cleaner" because typically such operators are commutative anyway, meaning LHS and RHS have the same significance. - dyp