Kinds of containers

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 25 08:42:02 PDT 2015


On 10/23/2015 01:44 PM, deadalnix wrote:
> On Friday, 23 October 2015 at 11:03:37 UTC, Andrei Alexandrescu wrote:
>> On 10/22/15 1:09 AM, deadalnix wrote:
>>> The elephant in the room: make the template parameter's type qualifier
>>> transitive with the collection's qualifier.
>>
>> Could you please give more detail on this? Thanks! -- Andrei
>
> Sure. We have a problem when it come to collection in the fact that type
> qualifier do not turtle down as one would expect.
>
> Collection!T and Collection!const(T) are 2 completely different types.
> There is a good reason for this : static if (is(T == const)) { ... } .
> As a result thing like :
>
> void foo(T)(const Collection!const(T) c) {}
> void main() {
>    Collection!T c;
>    foo(c); // Error, GTFO !
> }

Makes sense. The way I like to think about it is in terms of 
compatibility with built-in types such slices. This code works:

void foo(T)(const T[] c) {}
void main() {
   int[] c;
   foo(c); // fine
}

> With the different qualifiers and implicit conversion, thing become
> quite tricky. You can simulate them partially with a set of carefully
> crafted alias this (but not having multiple alias this doesn't make
> things any simpler) but there is the monster of mutually recursive
> template instanciation that is lurking.
>
> As far as i know, jmdavis had some good work done on this, but it was
> far from perfect.

Thanks, I see. The way I see it is as the work of "alias this"; any 
failure can be ascribed as a burden on the alias this definition.

Jonathan, do you have a link to your work?


Andrei



More information about the Digitalmars-d mailing list