Ambiguity issue with expanding and evaluating single template type parameter enums
data pulverizer
data.pulverizer at gmail.com
Mon Dec 27 21:05:51 UTC 2021
Hello,
I'm generating code using mixins and one of my mixins expands to
something like this:
```
adder(MyType!MyEnum.INTEGER(), MyType!MyEnum.STRING());
```
`MyType!MyEnum.STRING` is generated with `T.stringof `. I get the
error:
```
Error: template instance `MyType!(MyEnum)` does not match
template declaration `MyType(MyEnum type)
```
and if I manually amend the code to this:
```
adder(MyType!(MyEnum.INTEGER)(), MyType!(MyEnum.STRING)());
```
It runs fine. It looks like the ambiguity of UFCS and type is
messing things up. This is a simplified example. Since the code
is being generated automatically in many places I can't go round
adding the brackets.
A simplified functional example is given below:
```
import std.stdio: writeln;
enum MyEnum
{
DOUBLE = 0,
STRING = 1,
INTEGER = 2
}
struct MyType(MyEnum type)
{}
auto getValue(T: MyType!U, alias U)(T x)
{
return U;
}
auto adder(T, U)(T x, U y)
{
return getValue(x) + getValue(y);
}
void main()
{
writeln("instance: ", adder(MyType!MyEnum.INTEGER(),
MyType!MyEnum.STRING()));
}
```
More information about the Digitalmars-d-learn
mailing list