CRoaring icon indicating copy to clipboard operation
CRoaring copied to clipboard

Adding standard-conforming iterators for C++

Open madscientist opened this issue 1 year ago • 4 comments

A few months ago I added a standards-conforming iterator to the C++ interface for 32bit croaring. It's always frustrated me that the iterator support in the C++ interface isn't "right". For example, a conforming forward iterator needs to be an lvalue, but this means an iterator struct can't actually be empty/have no content. The "trick" of using a static "empty" iterator for end() also really bothers me as just "icky" :).

I find this page invaluable for considering iterator classes in C++: https://cplusplus.com/reference/iterator/

The iterators we have are kind of a mishmash of various things but the only type of iterator they actually fully implement is the simple input iterator. All other classes of iterator have something missing.

On the other hand, it's not clear to me that we can implement a "correct" STL iterator without any backward-compatibility issues with what's there now.

What are peoples' thoughts about this.

madscientist avatar Sep 30 '24 22:09 madscientist

For header-only C++, we can always mix and match two behaviours... either through macros or some other means.

lemire avatar Oct 01 '24 01:10 lemire

Also, we should precisely address what we mean by "backward-compatibility issues". Is it practically significant?

lemire avatar Oct 01 '24 14:10 lemire

Well it won't be clear until the implementation is complete. A big part of that will be enhancing the tests for C++ iterators, which are currently a bit too minimal.. But what I was referring to would not just be an issue of recompiling the code or using a shared library. I am more concerned if code that currently uses iterators will have to change in some way. Maybe that won't be necessary. I agree the backward-compatibility situation needs to be clear in the commit message.

If this seems like something people are interested in I'll try to find time to polish my changes and put up a PR.

madscientist avatar Oct 01 '24 18:10 madscientist

@madscientist I can't speak for everyone, but I can say that I would welcome progress on this front.

It is entirely possible that I am at the root of the problem you are trying to solve btw.

lemire avatar Oct 01 '24 20:10 lemire