Does `is` expression with template alias need fixing.

kdevel kdevel at vogtner.de
Thu Mar 23 12:40:47 UTC 2023


On Thursday, 23 March 2023 at 00:36:12 UTC, Elfstone wrote:
> Yes, I can.
>
> ```C++
> template <typename T>
> using Vector3 = Matrix<T, 3, 1>;
>
> template <typename T>
> void foo(const Vector3<T>& v) {
> }
>
> int main() {
> 	foo(Vector3<float>());
> }
> ```
> I can declare parameters with Vector3\<T\>, and it gets me the 
> right T, which is all I need.
>
> D allows me to declare template alias parameter but it matches 
> nothing at all. Then why allow people to write template alias 
> parameters at all?

It is interesting that this

```
struct B (T, V) { }

alias A = B!(double, void);

void f (A) { }

void main ()
{
    A a;
    f (a);
    B!(double, void) b;
    f (b); // works
}
```

compiles while the version with incomplete specialization 
requires a version of `f` not using the alias template in the 
parameter list:

```
struct B (T, V) { }

alias A (T) = B!(T, void);

// void f (T) (A!(T)) { } // fail
void f (T) (B!(T, void)) { } // cannot use A!T here, why not?

void main ()
{
    A!double a;
    f (a); // does not call void f (T) (A!(T))
    B!(double, void) b;
    f (b); // does not call void f (T) (A!(T))
}
```

In the failing case dmd says

```
vm.d(11): Error: none of the overloads of template `vm.f` are 
callable using argument types `!()(B!(double, void))`
vm.d(5):        Candidate is: `f(T)(A!T)`
vm.d(13): Error: none of the overloads of template `vm.f` are 
callable using argument types `!()(B!(double, void))`
vm.d(5):        Candidate is: `f(T)(A!T)`
```

It seems that dmd views `A!double` and `B!(double, void)` as 
different types which they aren't. Isn't there an alias-expansion 
phase during compilation?

[1] https://issues.dlang.org/show_bug.cgi?id=23798


More information about the Digitalmars-d mailing list