Does `is` expression with template alias need fixing.

FeepingCreature feepingcreature at gmail.com
Tue Mar 21 08:58:29 UTC 2023


On Tuesday, 21 March 2023 at 08:43:59 UTC, Dom Disc wrote:
> But if we make it work for struct, it will work with every type 
> (with a little extra boilerplate):
>
> ```
> template identity(int i) {
>    struct wrapper { int w = i; }
>    enum identity = w;
> }
>
> void foo() {
>     enum five = identity!5;
>     static assert(is(five == identity!y, int y) && y == 5);
> }
> ```
>
> And with some new lowering we could even get rid of that 
> boilerplate.
> E.g. simply add the 'parent' property to the template 
> parameters automatically if we detect that it is used in this 
> way somewhere (but that may cost some compile time).

Define "somewhere"? Because `identity` can be compiled in a 
different *compiler call* to `foo`. Anyways, you *cannot* add a 
parent property to `int`, ever, because then it would be a 
*different type.* You can wrap `int` in a struct, you can wrap 
everything in a struct, and then `is` will just work today. But 
that's cumbersome.

Why not just steal traits from Rust? Then `Matrix` can implement 
`Vector` iff `N=1`, and the function can just take a `Vector` 
parameter.


More information about the Digitalmars-d mailing list