RFC on range design for D2
Sean Kelly
sean at invisibleduck.org
Tue Sep 9 11:28:33 PDT 2008
Andrei Alexandrescu wrote:
>
> Then there remains the problem:
>
> void bump(R, V)(R r)
> {
> for (; !r.isEmpty; r.next) ++r.first;
> }
>
> bump(charArraySucker); // bogus
>
> Sigh...
And I suppose you don't want to return a const reference from first()
because the user may want to operate on the value, if only on a
temporary basis? Let's say:
P findFirst(P, R, C)( R r, C c )
{
for( ; !r.isEmpty; r.next )
{
// modify the temporary because a new element is expensive
// to copy-construct
if( auto p = c.contains( ++r.first ) )
return p;
}
return P.init;
}
Hm... must the implementation prevent stupid mistakes such as your
example? Ideally, yes. But I don't see a way to do so and yet allow
for routines like findFirst() above.
Sean
More information about the Digitalmars-d-announce
mailing list