Containers

jmh530 john.michael.hall at gmail.com
Wed Sep 1 01:38:49 UTC 2021


On Wednesday, 1 September 2021 at 00:26:33 UTC, Paul Backus wrote:
> [snip]
>
> 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))`. For all it knows, you could have 
> written code like the following:
>
> ```d
> struct Vector(T)
> {
>     static if (is(T == const)) {
>         // do one thing
>     } else {
>         // do something completely different
>     }
> }
> ```
>
> Maybe in some restricted cases it could examine the 
> uninstantiated template, determine that there's no funny 
> business going on, and conclude that the implicit conversion is 
> valid--but this kind of heuristic-based approach tends to be 
> very brittle and compose poorly (exhibit A: [issue 1807][1]).
>
> In general, if we want the compiler to know that a conversion 
> from one template instantiation to another is valid, we are 
> going to have to [prove it by construction][2]--which is to 
> say, by writing a function (like a constructor or an `opCast` 
> overload) that actually performs the conversion.
>
> [1]: https://issues.dlang.org/show_bug.cgi?id=1807
> [2]: https://en.wikipedia.org/wiki/Constructive_proof

I think you make some good points here.

My recollection is that opHeadMutable [1] was intended as a way 
to inform the compiler that the conversion is valid.

On issue 1807, as much as I want that enhancement, I just hope 
that there is a general solution to resolve it and not just a 
heuristic-based one.

[1] 
https://forum.dlang.org/post/cpxfgdmklgusodqouqdr@forum.dlang.org


More information about the Digitalmars-d mailing list