I want to define freestanding operators (op==, op<, etc.) for my iterator class, but I'm struggling with the proper syntax:
template<class A>
class Container {
public:
template<class B>
class Iterator {
public:
explicit Iterator(B value) : value_(value) {};
friend bool operator==(const Iterator& lhs, const Iterator& rhs);
private:
A value_;
};
};
// Fails to compile:
template<class A>
template<class B>
bool operator==(const typename Container<A>::Iterator<B>& lhs, const typename Container<A>::template Iterator<B>& rhs) {
return lhs.value_ == rhs.value_;
}
Container<int>::Iterator<double> it1{42.0};
Container<int>::Iterator<double> it2{42.0};
assert(it1 == it2);