https://issues.dlang.org/show_bug.cgi?id=23278
RazvanN <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #3 from RazvanN <[email protected]> --- (In reply to Marcelo Silva Nascimento Mancini from comment #0) > This trivial code fails to compile with the error message: > `onlineapp.Test2.mxString!(oops).mxString` need `this` to access member > `mxString` > > ```d > class Test2 > { > string oops; > mixin(mxString!(oops)); > } > enum mxString(alias c)() > { > return ""; > } > ``` > > This should compile as there is no dependent usage on "this". Plus, the > message is obviously wrong as there is no member named `mxString`. > > A real use case for that is: > ```d > enum mxString(alias c)() > { > return typeof(c).stringof~" "~c.stringof~c.stringof~";"; > } > ``` > Which does not depends on "this", as some code like `mxString!(typeof(oops), > oops.stringof)` would work. > > Mixin template does not have this limitation, so, I believe a normal > function should not too. I don't really understand what you are trying to achieve here? mixin templates are used to insert declarations in a scope. If you want to mixin a function, why not declare mxString as: ``` class Test2 { string oops; mixin mxTempl!(oops); } mixin template mxTempl(alias c) { enum mxString() { return ""; } } ``` This is an enhancement request at best. However, I don't really see the point of this code. Why would you want to insert a publicly declared template in the scope of an aggregate? Why not just call the function template when it is needed with the appropriate template parameter? --
