ball icon indicating copy to clipboard operation
ball copied to clipboard

BaseIterator difference_type typedef problematic

Open dstoeckel opened this issue 9 years ago • 0 comments

Currently BaseIterator defines the difference_type as Position. Unfortunately many Composite-derived classes define Position as Composite*, which makes no sense as a difference_type. This breaks compatibility of our iterators with many STL algorithms.

For example the following code does not compile:

#include <BALL/KERNEL/protein.h>

#include <algorithm>

using namespace BALL;

int main() { 
  Protein p;

  std::count_if(p.beginResidue(), p.endResidue(),
                std::mem_fn(&Residue::isSelected));
}

Changing BaseIterator::difference_type unconditionally to std::ptrdiff_t (the STL default) fixes this. However I am not certain that this is the correct fix. Any ideas?

dstoeckel avatar Apr 20 '16 09:04 dstoeckel