How can I explicitly reference this template member?

Template members can be indirectly referred to if they are the only member of the template and if they share the template name:

template foo(int number)
    immutable int foo = number;

void main()
    writeln(foo!(123)); // Okay.


But what if I want to explicitly reference an element?

writeln(foo!(123).foo); // Error: attempts to access the foo property of int.


I have no good reason for this, but I feel it is possible.


source to share

2 answers

Epident templates are replaced with their values ​​when used. So, regarding the compiler, write



basically the same as the entry



And this is not legal. This line will lead to the exact same error you are getting. You shouldn't be able to access members of the template of the same name. They are intentionally opaque.



You can't - templates of the same name are opaque; you cannot attack them like that.



All Articles