July 30, 2013 Re: use template function without assignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Tuesday, 30 July 2013 at 20:34:32 UTC, Ali Çehreli wrote: > On 07/30/2013 12:09 PM, JS wrote: > > > I already stated why this is not a proper example, I'm not > using Pragma > > in run time code(for lack of a better term). > > > > module main; > > > > import std.stdio; > > > > > > template Pragma(alias amsg) > > { > > void Pragma(string file = __FILE__) > > { > > pragma(msg, amsg); > > } > > } > > > > template t() > > { > > Pragma!("help, this does not work!!!!!!!!!"); > > } > > > > void main() > > { > > enum msg = "hello"; > > Pragma!msg; > > t!(); > > } > > Thank you. Now we have something to work on. The program above produces the following error: > > Error: no identifier for declarator Pragma!"help, this does not work!!!!!!!!!" > > The error is fixed by adding a mixin: > > mixin Pragma!("help, this does not work!!!!!!!!!"); > Or just assigning it to enum... both are not great solutions... > Despite another error it actually works: > > hello > help, this does not work!!!!!!!!! <-- IT WORKED > Error: t!() has no effect > > The second error is fixed by another mixin: > > mixin t!(); > > Perhaps the example is too simplistic. Still, let's stay with it for further issues. > > Ali I think that such behavior should not be an error but possibly a warning, if at all. And if you cared to read what I initially posted you would realize I already explained the same thing. The example maybe more clear but I stated, maybe in some convoluted and jumped way, that Pragma doesn't work *in* templates.. "When I try to use void instead of string and do something like Pragma!(msg) I get an error that the template has no effect." and later "It's goal is to debug templates and essentially just wrapping pragma to supply the __FILE__ info automatically. e.g., instead of having to do pragma(msg, __FILE__~amsg); I want to do Pragma!(amsg); " |
Copyright © 1999-2021 by the D Language Foundation