digitalmars.D.learn - Reflection
- Joshua Niehus (16/16) Feb 27 2012 Hello,
- Jesse Phillips (2/18) Feb 27 2012 It is a template.
- Puming (2/3) Feb 27 2012 Is a template callable? So what's the isCallable and
- Jesse Phillips (6/9) Feb 27 2012 I suppose it could be considered a bug as it is mostly a
- Joshua Niehus (5/6) Feb 27 2012 I see, thanks.
- James Miller (7/13) Feb 27 2012 Not really, there might be, but not an obvious one. Its because
- Timon Gehr (4/9) Feb 27 2012 You can trivially test whether the symbol is callable with some specific...
- Jonathan M Davis (9/27) Feb 28 2012 writeln doesn't even really exist as far as the compiler is concerned un...
Hello, I dont understand the following snippet's output: import std.stdio, std.traits; void main() { writeln(isSomeFunction!(writeln)); writeln(isCallable!(writeln)); writeln("Yes I am..."); } /* OUTPUT */ false false Yes I am... If 'writeln' isn't a method/function and it's not callable, then what is it? Thanks, Josh
Feb 27 2012
On Tuesday, 28 February 2012 at 05:56:12 UTC, Joshua Niehus wrote:Hello, I dont understand the following snippet's output: import std.stdio, std.traits; void main() { writeln(isSomeFunction!(writeln)); writeln(isCallable!(writeln)); writeln("Yes I am..."); } /* OUTPUT */ false false Yes I am... If 'writeln' isn't a method/function and it's not callable, then what is it? Thanks, JoshIt is a template.
Feb 27 2012
It is a template.Is a template callable? So what's the isCallable and isSomeFunction equivalent for templates?
Feb 27 2012
On Tuesday, 28 February 2012 at 06:26:38 UTC, Puming wrote:I suppose it could be considered a bug as it is mostly a syntactic request/check. I'd expect assert(isCallable!(writeln!string)) to be true. But as it is callable without explicit instantiation...It is a template.Is a template callable? So what's the isCallable and isSomeFunction equivalent for templates?
Feb 27 2012
On Tuesday, 28 February 2012 at 06:10:11 UTC, Jesse Phillips wrote:It is a template.I see, thanks. And I bet its not possible to figure out if a template is a "function template" or a "class template" etc...
Feb 27 2012
On 28 February 2012 19:27, Joshua Niehus <jm.niehus gmail.com> wrote:On Tuesday, 28 February 2012 at 06:10:11 UTC, Jesse Phillips wrote:Not really, there might be, but not an obvious one. Its because templates can hold multiple types of declarations, not just functions or classes. The "eponymous template" pattern you see normally is not mandatory. -- James MillerIt is a template.I see, thanks. And I bet its not possible to figure out if a template is a "function template" or a "class template" etc...
Feb 27 2012
On 02/28/2012 07:27 AM, Joshua Niehus wrote:On Tuesday, 28 February 2012 at 06:10:11 UTC, Jesse Phillips wrote:You can trivially test whether the symbol is callable with some specific arguments, if that helps: is(typeof(writeln(arg1,arg2,arg3)))It is a template.I see, thanks. And I bet its not possible to figure out if a template is a "function template" or a "class template" etc...
Feb 27 2012
On Tuesday, February 28, 2012 06:56:10 Joshua Niehus wrote:Hello, I dont understand the following snippet's output: import std.stdio, std.traits; void main() { writeln(isSomeFunction!(writeln)); writeln(isCallable!(writeln)); writeln("Yes I am..."); } /* OUTPUT */ false false Yes I am... If 'writeln' isn't a method/function and it's not callable, then what is it?writeln doesn't even really exist as far as the compiler is concerned until it's been instantiated. So, testing writeln isn't going to work. You need to either test a specific instantiation (e.g. isSomeFunction!(writeln!string))), or you need to just test that particular call works (e.g. is(typeof(writeln(arg)))). The second is probably better, since that's generally what you really care about - is it compilable with the given set of arguments. - Jonathan M Davis
Feb 28 2012