Argument deduction for alias templates
Paul
paultjeadriaanse at gmail.com
Thu Jan 7 16:18:53 UTC 2021
While trying out eponymous alias templates, I noticed they don't
feature argument deducitions at all, even though the compiler
knows what types are given, as can be told from the exceptions
it's giving. Additonally, eponymous alias templates seem to only
function when at least 1 argument is given, even if default
values are used, which is slightly disappointing as this is not
the case for eponymous function templates.
Random example from the top of my head:
> alias Vec(Kind = float, int size = 1) = Kind[size];
> alias Vec2(int size = 1, Kind = float) = Kind[size];
>
> void foo(Kind = float, int size = 1)(Kind[size] a) {
> writeln(a);
> }
>
> // Works
> char[5] a = "apple";
> foo(a);
> Vec!string b = ["0.3"];
>
> // Does not work
> Vec!float d = [0.1, 0.2];
> // mismatched array lengths, 1 and 2
> Vec2!1 c = ["apple"];
> // cannot implicitly convert expression ["apple"] of type
> string[] to float[]
> Vec f = [0.4];
> // template app.main.Vec(Kind = float, int size = 1) is used as
> a type
More information about the Digitalmars-d
mailing list