digitalmars.D.learn - Does is(f == function) work?
- Andrey Zherikov (4/4) Mar 08 2021 What am I doing wrong?
- Adam D. Ruppe (4/5) Mar 08 2021 try
- Andrey Zherikov (7/10) Mar 09 2021 Thanks!
- Adam D. Ruppe (5/7) Mar 09 2021 I actually don't know. The docs do say that function pointers
- Kyle Ingraham (3/15) Mar 09 2021 Does Unqual help here?:
- Boris Carvajal (4/16) Mar 09 2021 Not quite straightforward, but "void function()" is actually a
- Andrey Zherikov (2/22) Mar 09 2021 That's a trick! Thank you!
What am I doing wrong? void f() {} writeln(typeof(f).stringof); // prints "void()" writeln(is(f == function)); // prints "false"
Mar 08 2021
On Tuesday, 9 March 2021 at 02:50:11 UTC, Andrey Zherikov wrote:writeln(is(f == function)); // prints "false"try is(typeof(f) == function) it is kinda weird but that's the trick
Mar 08 2021
On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote:try is(typeof(f) == function) it is kinda weird but that's the trickThanks! Should it work for in this case as well? alias f = (){}; writeln(typeof(f).stringof); // prints "void function() pure nothrow nogc safe" writeln(is(typeof(f) == function)); // prints "false"
Mar 09 2021
On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote:Should it work for in this case as well? alias f = (){};I actually don't know. The docs do say that function pointers work differently - they match `is(typeof(f) == return)` but it isn't clear if it would match == function. You'd certainly think it would... but idk.
Mar 09 2021
On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote:On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote:Does Unqual help here?: https://dlang.org/phobos/std_traits.html#Unqualtry is(typeof(f) == function) it is kinda weird but that's the trickThanks! Should it work for in this case as well? alias f = (){}; writeln(typeof(f).stringof); // prints "void function() pure nothrow nogc safe" writeln(is(typeof(f) == function)); // prints "false"
Mar 09 2021
On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote:On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote:Not quite straightforward, but "void function()" is actually a pointer to function, you need to dereference it first: is(typeof(*f) == function)try is(typeof(f) == function) it is kinda weird but that's the trickThanks! Should it work for in this case as well? alias f = (){}; writeln(typeof(f).stringof); // prints "void function() pure nothrow nogc safe" writeln(is(typeof(f) == function)); // prints "false"
Mar 09 2021
On Tuesday, 9 March 2021 at 18:53:06 UTC, Boris Carvajal wrote:On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote:That's a trick! Thank you!On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote:Not quite straightforward, but "void function()" is actually a pointer to function, you need to dereference it first: is(typeof(*f) == function)try is(typeof(f) == function) it is kinda weird but that's the trickThanks! Should it work for in this case as well? alias f = (){}; writeln(typeof(f).stringof); // prints "void function() pure nothrow nogc safe" writeln(is(typeof(f) == function)); // prints "false"
Mar 09 2021