
Rogier van Dalen wrote:
On Thu, Jul 23, 2009 at 13:48, David Abrahams<dave@boostpro.com> wrote:
Hi Neil,
I'm sure someone already spoke to you about this, but just in case: Andrei Alexandrescu gave a very interesting presentation at BoostCon that was based on a "ranges only" approach that should eliminate issues like this one:
That looks very interesting. Is there any documentation on this out there? I found the slides:
http://www.boostcon.com/site-media/var/sphene/sphwiki/attachment/2009/05/08/...
and documentation for a D implementation: http://www.digitalmars.com/d/2.0/phobos/std_algorithm.html http://www.digitalmars.com/d/2.0/phobos/std_range.html
I'm wondering why "popFront()" is mutable and edits the range rather than return a range without the first element. The latter might allow compile-time heterogeneous sequences (like boost::fusion::vector) to conform to this range concept as well. I just realised you could then write a foreach function that works on both homogeneous and heterogeneous sequences basically like:
template <class Range, class Function> void foreach (Range range, Function function) { if (!range.empty()) { function (range.front()); foreach (range.popFront(), function); } }
Is popFront() mutable just for efficiency? Or is there something else I'm missing?
It's only efficiency. I was very attracted to popFront returning the new range (100% functional interface!) but I gave up for efficiency reasons. I didn't want iteration with ranges to be cool and iteration with other means to be efficient. Andrei