Does `is` expression with template alias need fixing.

Elfstone elfstone at yeah.net
Wed Mar 22 10:43:15 UTC 2023


On Wednesday, 22 March 2023 at 09:22:01 UTC, FeepingCreature 
wrote:
> On Wednesday, 22 March 2023 at 07:25:04 UTC, Elfstone wrote:
>> I wouldn't call what I want a new feature, but a fix to this 
>> big hole in the language design (or implementation). People 
>> would expect an alias works the same as the original symbol, 
>> at least people need not care if they are using an alias from 
>> std (`Regex`), as long as the compiler will generate a warning 
>> where an alias might cause problems.
>
> Well, an alias works *the same as the original symbol,* that's 
> rather the problem. You can't infer the template instantiation 
> that produced the alias, because the compiler doesn't see the 
> alias after the fact, because "an alias member" is not a 
> lexical member in the same way that "a templated struct" is.
>
> My opinion is that we're several steps into an X-Y problem 
> here, where what we *actually want* is to indicate that a value 
> fulfills a certain constraint - "is a vector" - in a more 
> freeform fashion than template constraints allow us to, without 
> having to write lots of `isVector` type predicates, in a way 
> that's legible to the typesystem. I think something like type 
> traits or typeclasses would fulfill this need in a cleaner way 
> and also make a lot of range code better.

I don't know how C++ compilers resolve `template using` just fine.

```C++
template <typename T>
using Vector3 = Matrix<T, 3, 1>;
```

I declare an alias and I use it everywhere. It acts as a natural 
constraint. I never needed `isVector3` with my old C++ code. I 
expected D could do the same, and was really frustrated when I 
found out it couldn't. Even more frustrated when I read Steven's 
reply, that the bug with `is` has been there for 16 years.

When the compiler allows people to use template aliases as 
template function parameters, it should make it work, or reject 
it aloud. Maybe some future system can save the day, but does it 
mean the old `alias` will just be left bugged?



More information about the Digitalmars-d mailing list