[phobos] is*Range + Qualified Types

Andrei Alexandrescu andrei at erdani.com
Wed Aug 11 22:43:57 PDT 2010


On 08/12/2010 12:05 AM, Shin Fujishiro wrote:
> David Simcha<dsimcha at gmail.com>  wrote:
>> I'm looking to go on a major debugging spree and make std.range work
>> with const ranges.  For example, the following should work:
>>
>> import std.range, std.algorithm;
>>
>> void main() {
>>       const foo = map!"a ^^ 2"([1,2,3,4,5]);
>>       auto myRetro = retro(foo);
>> }
>
> Could you elaborate why?
>
> Ranges with const elements must be common; but what's the point of
> const ranges?  Const random access ranges are usable, but other const
> ranges seem to be useless since popFront and popBack can't be const.

I think the main argument is that currently most of std.algorithm 
doesn't work with const arrays, which have a simple "tail-const" 
version. const(T[]) is implicitly convertible to const(T)[].

That doesn't apply to most other ranges, which don't have an obvious 
"tail-const" version.

David, I think we need to think through a bit more before proceeding. 
The way I assume you want to proceed is to essentially add a special 
function signature for each algorithm and have it forward to the peeled 
version. Perhaps we could look at a simpler solution, e.g. one that 
would involve a language change.


Andrei


More information about the phobos mailing list