Robert,
On Tuesday, July 24, 2012, Robert Jones wrote:
I have a class that hands out a sequence of Things through a
getNextThing() interface, ie.,
struct Thing { };
struct ThingFeed
{
Thing * getNextThing( );
};
returning null when there's no more things. I'd like to be
able to feed this into the Boost range-based algorithms, something
like
Since we are not in a position to offer range primitives, there is more work required than one would like. To maximize interoperability with algorithms and existing C++ code the ranges in Boost.Range are limited to being implemented on top of iterators. Therefore the getNextThing() would need to be part of an increment operator / operators upon a forward traversal iterator. This is not difficult to implement using Boost.Iterator.
If you do not require this level of interoperability and you are merely using your own algorithms, then it is quite reasonable to use your own range primitives, perhaps similar in nature to the ones proposed by Andrei Alexandrescu.
boost::for_each( thingFeedProxy | filter( someCondition ), doSomething );
But it's not clear to me how or if I can represent my ThingFeed as a range.
Any thoughts or advice appreciated.
To represent the example shown is tricky. Normally it is not this difficult because one implements containers to interoperate with the STL and therefore have iterators. I do agree that the best ultimate solution is to have well-specified Range Primitive Concepts and algorithms similar to those provided by Boost.Range that operate upon these primitive types.
The reason you cannot do this today is simply because I'm too rubbish and slow to have done it yet. I am making a stronger effort to clear my TRAC tickets and then hopefully gain some time to release a new wave of features.
Thx, Rob
Sorry,
Neil Groves