What features of D are you using now which you thought you'd never goint to use?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Jun 23 07:39:55 PDT 2013


On 6/23/13 4:04 AM, monarch_dodra wrote:
> R range;
> auto r3 = findSplit(range);
> void do_it(r3[0]);
> void do_it(r3[1]);
> void do_it(r3[2]);
>
> This will actually instantiate 2 different do_it functions.

Yah, this is a good summary. If individual iterators are accessible, 
findSplit can return three ranges of the same type. Otherwise, generally 
findSplit must return ranges of distinct types.

Note, however, that if the initial range is strictly forward, the three 
resulting range may not have the same type as the initial range. As a 
simple example, findSplit over a singly-linked list cannot return three 
singly-linked lists.

(I don't think template bloat is the main problem here, instead a sort 
of matter of principles.)

Again, we can make things work by introducing a primitive for 
bidirectional ranges:

R before(R r1, R r2);

Assuming r2 is reachable from r1, returns the portion of r1 that lies 
before r2. (Definition: a range r2 is reachable from another range r1 if 
calling r1.popFront() repeatedly will at some point make r1.front and 
r2.front refer to the same value.)


Andrei


More information about the Digitalmars-d mailing list