range and algorithm-related stuff

Steven Schveighoffer schveiguy at yahoo.com
Mon Jan 26 18:48:20 PST 2009


"Andrei Alexandrescu" wrote
> Probably many people would expect to just write this:
>
> void foo(in SomeRange range) { ... }
>
> and have foo look at the range and its elements no problem, without 
> actually iterating through the range.

Consider that some type  const Range!(T), where T is a reference that 
contains the data to be iterated can be copied without casting to a 
Range!(const T)

I think you even filed an enhancement on this, if I'm not mistaken.  So a 
void foo(in SomeRange range) can be rewritten as void foo(ConstSomeRange), 
and you should technically be able to pass a const(SomeRange) into it.  This 
is because a range is a struct, and aside from the reference to the data, 
everything else is stack local.

Assuming ConstSomeRange is the same as SomeRange but with the data reference 
being const.

-Steve 





More information about the Digitalmars-d mailing list