digitalmars.D.learn - Template alias parameter does not accept functions
- Dicebot (10/10) Feb 27 2013 Looking here:
- Dicebot (2/2) Feb 27 2013 Actually it looks like a somewhat broken behavior as it works for
- Nick Treleaven (11/19) Feb 27 2013 This has sometimes come up in the NG, with some support for the feature....
- Nick Treleaven (3/12) Feb 27 2013 Actually I may have misunderstood your question. Anyway, please show the...
- Dicebot (2/2) Feb 27 2013 Ye, lambda litteral issue is different one.
- Andrej Mitrovic (9/11) Feb 27 2013 The problem is not in the alias, it's in the call to .stringof, the
- Dicebot (3/3) Feb 27 2013 Fuck. Optional. Parens.
- Nick Treleaven (16/18) Feb 27 2013 The problem may be related to optional parentheses and stringof, and may...
Looking here: http://dlang.org/template.html#TemplateAliasParameter There are no function symbols in the list. And quick check that it won't compile. Two questions arise: a) Why so? b) Is there a workaround? I have started writing some code with UDAs and do want to pass a function to utility template to process without loosing attribute information, thus the issue.
Feb 27 2013
Actually it looks like a somewhat broken behavior as it works for parameter-less functions.
Feb 27 2013
On 27/02/2013 15:20, Dicebot wrote:Looking here: http://dlang.org/template.html#TemplateAliasParameter There are no function symbols in the list. And quick check that it won't compile. Two questions arise: a) Why so? b) Is there a workaround?This has sometimes come up in the NG, with some support for the feature. See also: http://d.puremagic.com/issues/show_bug.cgi?id=7308 bearophile shows the workaround - use another template: template ID(alias a){alias a ID;} void main(){ alias ID!(x => x ^^ 2) sqrTemplate; } On 27/02/2013 17:17, Dicebot wrote:Actually it looks like a somewhat broken behavior as it works for parameter-less functions.I'm not sure what you mean, can you show the code it works for?
Feb 27 2013
On 27/02/2013 17:38, Nick Treleaven wrote:On 27/02/2013 15:20, Dicebot wrote:Actually I may have misunderstood your question. Anyway, please show the code that doesn't work.Looking here: http://dlang.org/template.html#TemplateAliasParameter There are no function symbols in the list. And quick check that it won't compile. Two questions arise: a) Why so? b) Is there a workaround?
Feb 27 2013
Ye, lambda litteral issue is different one. My code example: http://dpaste.1azy.net/b06370ea
Feb 27 2013
On 2/27/13, Dicebot <m.strashun gmail.com> wrote:Ye, lambda litteral issue is different one. My code example: http://dpaste.1azy.net/b06370eaThe problem is not in the alias, it's in the call to .stringof, the compiler attempts to invoke the function passed and then call .stringof on it. If all you want is the name of the function you can use a trait: template check(alias Symbol) { enum check = __traits(identifier, Symbol); }
Feb 27 2013
Fuck. Optional. Parens. Thank you. I have tried some other code than .stringof but guess it invoked Symbols somewhere silently, too.
Feb 27 2013
On 27/02/2013 18:06, Dicebot wrote:Ye, lambda litteral issue is different one.OK.My code example: http://dpaste.1azy.net/b06370eaThe problem may be related to optional parentheses and stringof, and may be a compiler bug. You can pass function names as a template alias parameter: import std.stdio; int f(int i) {return i^^2;} template check(alias Symbol) { enum check = Symbol(5); // CTFE } void main() { //~ pragma(msg, f.stringof); //error writeln(check!f); // 25 }
Feb 27 2013