Kinds of containers

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 22 14:27:57 PDT 2015


On Thursday, 22 October 2015 at 17:13:48 UTC, Jonathan M Davis 
wrote:
> On Thursday, 22 October 2015 at 16:29:19 UTC, bitwise wrote:
>> Maybe look at the code next time before you LOL......
>
> My point would be the same regardless. Range!(const T) and 
> const(Range!T) - and Container!(const T) and const(Container!T) 
> - have no relation as far as the compiler is concerned, and 
> that makes dealing with const correctly a royal pain - 
> particularly if you want a range to act like an array like it's 
> supposed to be able to do (at least insofar as they have the 
> same operations). You asked what deadalnix meant by
>
>> The elephant in the room: make the template parameter's type 
>> qualifier transitive
>> with the collection's qualifier.
>
> and I tried to explain.
>
> - Jonathan M Davis

I'm not even sure you're talking about the same thing as 
deadalnix, and I think I have already done what he's asking.

example:
   List!int a = [1, 2];
   writeln( typeof(a[]).stringof );
   writeln( typeof(a[].front).stringof );
   writeln( is(typeof({ a[].popFront(); })).stringof );

   const(List!int) b = [1, 2];
   writeln( typeof(b[]).stringof );
   writeln( typeof(b[].front).stringof );
   writeln( is(typeof({ b[].popFront(); })).stringof );

output:
   Range!(ListBase!int)
   int
   true
   Range!(const(ListBase!int))
   const(int)
   true


Of course, neither of the following are possible because of the 
design of D's const.

import std.container;
Array!(const(int)) a;

import collections;
List!(const(int)) b;

Both will produce compilation errors.

     Bit






More information about the Digitalmars-d mailing list