Containers

Steven Schveighoffer schveiguy at gmail.com
Wed Sep 1 11:04:41 UTC 2021


On 8/31/21 8:26 PM, Paul Backus wrote:
> On Tuesday, 31 August 2021 at 23:56:51 UTC, Steven Schveighoffer wrote:
>>> To put it bluntly, I have no idea how to achieve this. And I don't 
>>> think we'll have a good set of collection before this is sorted out.
>>
>> I had an idea a long time ago, but ashamedly never brought it to 
>> fruition. But long story short, I think we need a way to specify 
>> "tail" for modifiers, and allow implicitly casting the head. Then 
>> you'd have `tailconst(Vector!int)`, and you are good. I actually had a 
>> decent syntax for it, but I'm not sure it would fly anyway.
> 
> One problem I can forsee with this approach is that, from the compiler's 
> point of view, there is not necessarily any predictable relationship 
> between `qualifier(Template!T)` and `Template!(qualifier(T))`.

It's possible to forward, i.e.:

```d
template Vector(T) if (isConst!T) { alias Vector = 
tailconst(.Vector!(Unqual!T)); }
```

If you look at arrays, `const(T)[]` is the same as `tailconst(T[])`. 
This would be similar.

The problem I have with any other approach is that the compiler doesn't 
understand the relationships, and you will run into weird corner cases. 
It can't correctly add or strip the qualifier to the correct members 
when calling compatible functions.

-Steve


More information about the Digitalmars-d mailing list