Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseIterator difference_type typedef problematic #580

Open
dstoeckel opened this issue Apr 20, 2016 · 0 comments
Open

BaseIterator difference_type typedef problematic #580

dstoeckel opened this issue Apr 20, 2016 · 0 comments

Comments

@dstoeckel
Copy link
Contributor

dstoeckel commented Apr 20, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants