On Thursday, 27 February 2014 at 21:24:20 UTC, Tobias Pankrath wrote:
On Thursday, 27 February 2014 at 21:09:45 UTC, Ben Jones wrote:

My question is: which features of the D range abstraction allow zip to work the way we expect? What C++isms were left behind to make this work?

Many items in std.algorithm / std.range make use of static if to provide the most capable return types. I.e. if you zip to RA ranges than zip will return a random access range, too.

See https://github.com/D-Programming-Language/phobos/blob/master/std/range.d#L4988

That can be done in C++ too (albeit less elgantly) with tag dispatch or enable if, or whatever. The big issue I ran into was dealing with the semantics of iterator dereferencing. I'm not sure anyone has come up with a way to define an iterator whose dereference operator returns a reference type when dealing with a zipped range in C++.

It seems that somehow D's range abstraction avoids that issues somehow, but I don't quite understand how.

Reply via email to