I had my own working iterator to move the pixels in the image horizontally or vertically. The template parameter can be const or not (a neat trick from Dr. Dobb's ).
Then I realized that there is a std::iterator base class, and I thought that I would make my stuff more STLly and inherit it.
Unfortunately, now Visual Studio 2012 (version 11.0.60315.01 Update 2) will no longer compile it. I really managed to get the stackoverflow compiler. This post is:
Error 1 error C1063: compiler limit: compiler stack overflow d: \ ... \ source.cpp 42 1 ConsoleApplication3
A very stripped down version of my class looks like this:
#include <iterator> // This comes from the outer image class. typedef float color_type; template<bool IS_CONST = false> struct Iterator : public std::iterator<std::random_access_iterator_tag, color_type> { // This is myself... typedef Iterator<IS_CONST> iterator; // ... and my variants. typedef Iterator<true> const_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; // Make base class typedefs available. typedef typename iterator::value_type value_type; typedef typename iterator::difference_type difference_type; // My own typedefs to deal with immutability. typedef value_type const & const_reference; typedef typename std::conditional<IS_CONST, const_reference, typename iterator::reference>::type reference; Iterator() : _position(nullptr), _step() { } Iterator(value_type * const position, difference_type const step) : _position(position), _step(step) { } iterator const operator-(difference_type n) const { return iterator(*this) -= n; } difference_type operator-(iterator const rhs) const { assert(_step == rhs._step); return (_position - rhs._position) / _step; } protected: value_type * _position; difference_type _step; }; int main() { float a = 3.141f; // Instanciate all variants. Iterator<false> empty; Iterator<true> const_empty; Iterator<false> some(&a, 5); Iterator<true> const_some(&a, 5); return 0; }
Removing one of the two operator- makes the compiler happy.
Can someone explain to me what the problem is? Or is it even better to fix it?
thanks
Update: Oh, by the way, GCC 4.7.2 happily compiles it .
source share