digitalmars.D.learn - function is not function
- Ellery Newcomer (10/10) Sep 21 2012 solution is to use std.traits, but can someone explain this to me?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (15/25) Sep 21 2012 You have probably tried the following already:
- bearophile (18/19) Sep 21 2012 Maybe pragma(msg) needs to print function pointer types with a
- Ellery Newcomer (10/12) Sep 21 2012 No, but that's also not very generic.
- bearophile (11/20) Sep 21 2012 There is a subtle difference between function type, type of
- Ellery Newcomer (2/3) Sep 21 2012 code in pyd suggests this evaluated to true once upon a time.
- Timon Gehr (2/5) Sep 21 2012 I don't think it ever did. It is just very easy to get wrong.
- Jonathan M Davis (5/17) Sep 21 2012 Sorry if this ends up being a double-post, but the post I made hours ago...
- Don Clugston (9/19) Sep 26 2012 The 'function' keyword is an ugly wart in the language. In
solution is to use std.traits, but can someone explain this to me? import std.stdio; void main() { auto a = { writeln("hi"); }; pragma(msg, typeof(a)); // void function() pragma(msg, is(typeof(a) == delegate)); // nope! pragma(msg, is(typeof(a) == function)); // nope! }
Sep 21 2012
On 09/21/2012 12:59 PM, Ellery Newcomer wrote:solution is to use std.traits, but can someone explain this to me? import std.stdio; void main() { auto a = { writeln("hi"); }; pragma(msg, typeof(a)); // void function() pragma(msg, is(typeof(a) == delegate)); // nope! pragma(msg, is(typeof(a) == function)); // nope! }You have probably tried the following already: pragma(msg, is(typeof(a) == void function())); Regardless, I think it is a bug because the documentation says that the 'function' keyword alone should work: http://dlang.org/expression.html#IsExpression <quote> is ( Type == TypeSpecialization ) The condition is satisfied if Type is semantically correct and is the same type as TypeSpecialization. If TypeSpecialization is one of struct union class interface enum function delegate const immutable shared then the condition is satisifed if Type is one of those. </quote> Ali
Sep 21 2012
Ellery Newcomer:Maybe pragma(msg) needs to print function pointer types with a "*", to help remember it's a pointer: int foo1() pure nothrow safe { return 0; } void main() { static assert(is(typeof(foo1) == function)); auto foo2 = { return 0; }; static assert(is(typeof(*foo2) == function)); pragma(msg, typeof(foo1)); pragma(msg, typeof(foo2)); } Prints: pure nothrow safe int() int function() pure nothrow safe From such printout I am not able to tell the first one is a function type and the second is the type of a function pointer :-( Bye, bearophilepragma(msg, typeof(a)); // void function()
Sep 21 2012
On 09/21/2012 01:10 PM, Ali Çehreli wrote:You have probably tried the following already: pragma(msg, is(typeof(a) == void function()));No, but that's also not very generic. void main() { auto a = { return 1; }; pragma(msg, is(typeof(a) == void function())); // nope! pragma(msg, typeof(a)); // void function() pure nothrow safe } guess what I'm fighting with just now
Sep 21 2012
Ellery Newcomer:import std.stdio; void main() { auto a = { writeln("hi"); }; pragma(msg, typeof(a)); // void function() pragma(msg, is(typeof(a) == delegate)); // nope! pragma(msg, is(typeof(a) == function)); // nope! }There is a subtle difference between function type, type of function pointer and delegate type. int foo1() { return 0; } void main() { static assert(is(typeof(foo1) == function)); auto foo2 = { return 0; }; static assert(is(typeof(*foo2) == function)); } Bye, bearophile
Sep 21 2012
On 09/21/2012 01:17 PM, bearophile wrote:code in pyd suggests this evaluated to true once upon a time.pragma(msg, is(typeof(a) == function)); // nope!
Sep 21 2012
On 09/21/2012 10:41 PM, Ellery Newcomer wrote:On 09/21/2012 01:17 PM, bearophile wrote:I don't think it ever did. It is just very easy to get wrong.code in pyd suggests this evaluated to true once upon a time.pragma(msg, is(typeof(a) == function)); // nope!
Sep 21 2012
On Friday, September 21, 2012 12:59:31 Ellery Newcomer wrote:solution is to use std.traits, but can someone explain this to me? import std.stdio; void main() { auto a = { writeln("hi"); }; pragma(msg, typeof(a)); // void function() pragma(msg, is(typeof(a) == delegate)); // nope! pragma(msg, is(typeof(a) == function)); // nope! }Sorry if this ends up being a double-post, but the post I made hours ago doesn't seem to be showing up, so I'm posting it again: http://stackoverflow.com/questions/11067972 - Jonathan M Davis
Sep 21 2012
On 21/09/12 21:59, Ellery Newcomer wrote:solution is to use std.traits, but can someone explain this to me? import std.stdio; void main() { auto a = { writeln("hi"); }; pragma(msg, typeof(a)); // void function() pragma(msg, is(typeof(a) == delegate)); // nope! pragma(msg, is(typeof(a) == function)); // nope! }The 'function' keyword is an ugly wart in the language. In void function() 'function' means 'function pointer'. But in is (X == function) 'function' means 'function'. Which is actually pretty much useless. You always want 'function pointer'. This is the only case where "function type" still exists in the language.
Sep 26 2012