digitalmars.D - How to distinguish a delegate from a function?
- Moritz Warning (10/10) Jul 12 2008 I try to check (at compile time) if an expression need to be called with...
- Bill Baxter (5/18) Jul 12 2008 I think these work:
- Moritz Warning (7/27) Jul 12 2008 Doesn't seem to work.
- Max Samukha (22/49) Jul 12 2008 I wish there was no inconsistency between delegate and function type
- Moritz Warning (4/58) Jul 13 2008 Yes, I noticed that is(typeof(&Foo.bar) == delegate) is true even it is
- Max Samukha (4/7) Jul 13 2008 The spec says nothing about exact semantics of type specializations of
- Oliver Dathe (22/22) Jul 12 2008 This works here:
- Moritz Warning (3/29) Jul 12 2008 Doesn't work for A.bar and A.foo (where foo is static and therefore don'...
- Matthias Walter (4/35) Jul 13 2008 I had this problem some months ago and found a solution: You can extract...
- Moritz Warning (2/47) Jul 14 2008 Great! I'm looking forward to make use of the solution.
I try to check (at compile time) if an expression need to be called with a context pointer or without. E.g.: I want to tell the difference between A.foo (no context pointer needed) and A.bar. class A { static void foo() {} void bar() {} } Any ideas?
Jul 12 2008
Moritz Warning wrote:I try to check (at compile time) if an expression need to be called with a context pointer or without. E.g.: I want to tell the difference between A.foo (no context pointer needed) and A.bar. class A { static void foo() {} void bar() {} } Any ideas?I think these work: static if(is(xxx == function)) static if(is(xxx == delegate)) --bb
Jul 12 2008
On Sun, 13 Jul 2008 06:03:53 +0900, Bill Baxter wrote:Moritz Warning wrote:Doesn't seem to work. Here are some of my tries (all evaluate to false): static if (is(Foo.get == delegate)) static if (is(Foo.init.get == delegate)) static if (is(typeof(Foo.get) == delegate)) static if (is(typeof(&Foo.get) == delegate))I try to check (at compile time) if an expression need to be called with a context pointer or without. E.g.: I want to tell the difference between A.foo (no context pointer needed) and A.bar. class A { static void foo() {} void bar() {} } Any ideas?I think these work: static if(is(xxx == function)) static if(is(xxx == delegate)) --bb
Jul 12 2008
On Sat, 12 Jul 2008 21:11:46 +0000 (UTC), Moritz Warning <moritzwarning web.de> wrote:On Sun, 13 Jul 2008 06:03:53 +0900, Bill Baxter wrote:I wish there was no inconsistency between delegate and function type specializations: class Foo { void foo() // typeof is void delegate() { } static void bar()// typeof is void function() { } } static assert(is(typeof(&Foo.init.foo) == delegate)); - ok static assert(is(typeof(&Foo.bar) == delegate)); - ok, though &Foo.bar is not a delegate. why is that? static assert(is(typeof(&Foo.bar) == function)); - fails because function type specialization checks for function type, not for function pointer type, which is imo inconsistent both with delegate type specialization and with function pointer declarationsMoritz Warning wrote:Doesn't seem to work. Here are some of my tries (all evaluate to false): static if (is(Foo.get == delegate)) static if (is(Foo.init.get == delegate)) static if (is(typeof(Foo.get) == delegate)) static if (is(typeof(&Foo.get) == delegate))I try to check (at compile time) if an expression need to be called with a context pointer or without. E.g.: I want to tell the difference between A.foo (no context pointer needed) and A.bar. class A { static void foo() {} void bar() {} } Any ideas?I think these work: static if(is(xxx == function)) static if(is(xxx == delegate)) --bb
Jul 12 2008
On Sun, 13 Jul 2008 09:43:41 +0300, Max Samukha wrote:On Sat, 12 Jul 2008 21:11:46 +0000 (UTC), Moritz Warning <moritzwarning web.de> wrote:Yes, I noticed that is(typeof(&Foo.bar) == delegate) is true even it is not an delegate. It's confusing, maybe it's a bug?On Sun, 13 Jul 2008 06:03:53 +0900, Bill Baxter wrote:I wish there was no inconsistency between delegate and function type specializations: class Foo { void foo() // typeof is void delegate() { } static void bar()// typeof is void function() { } } static assert(is(typeof(&Foo.init.foo) == delegate)); - ok static assert(is(typeof(&Foo.bar) == delegate)); - ok, though &Foo.bar is not a delegate. why is that? static assert(is(typeof(&Foo.bar) == function)); - fails because function type specialization checks for function type, not for function pointer type, which is imo inconsistent both with delegate type specialization and with function pointer declarationsMoritz Warning wrote:Doesn't seem to work. Here are some of my tries (all evaluate to false): static if (is(Foo.get == delegate)) static if (is(Foo.init.get == delegate)) static if (is(typeof(Foo.get) == delegate)) static if (is(typeof(&Foo.get) == delegate))I try to check (at compile time) if an expression need to be called with a context pointer or without. E.g.: I want to tell the difference between A.foo (no context pointer needed) and A.bar. class A { static void foo() {} void bar() {} } Any ideas?I think these work: static if(is(xxx == function)) static if(is(xxx == delegate)) --bb
Jul 13 2008
On Sun, 13 Jul 2008 11:31:30 +0000 (UTC), Moritz Warning <moritzwarning web.de> wrote:Yes, I noticed that is(typeof(&Foo.bar) == delegate) is true even it is not an delegate. It's confusing, maybe it's a bug?The spec says nothing about exact semantics of type specializations of that kind, so it may be a feature.
Jul 13 2008
This works here: template isCallableStatically(T) { static if (is(T==function) || is(typeof(*T)==function)) const bool isCallableStatically = true; else static if (is(T==delegate)) const bool isCallableStatically = false; else static assert (false); } template isCallableStatically(alias T) { const isCallableStatically = isCallableStatically!(typeof(&T)); } void fn() {} void main() { void dg() {} static assert (isCallableStatically!(fn)); static assert (!isCallableStatically!(dg)); static assert (isCallableStatically!(typeof(&fn))); static assert (!isCallableStatically!(typeof(&dg))); }
Jul 12 2008
On Sun, 13 Jul 2008 03:38:36 +0200, Oliver Dathe wrote:This works here: template isCallableStatically(T) { static if (is(T==function) || is(typeof(*T)==function)) const bool isCallableStatically = true; else static if (is(T==delegate)) const bool isCallableStatically = false; else static assert (false); } template isCallableStatically(alias T) { const isCallableStatically = isCallableStatically!(typeof(&T)); } void fn() {} void main() { void dg() {} static assert (isCallableStatically!(fn)); static assert (!isCallableStatically!(dg)); static assert (isCallableStatically!(typeof(&fn))); static assert (!isCallableStatically!(typeof(&dg))); }Doesn't work for A.bar and A.foo (where foo is static and therefore don't need an object)
Jul 12 2008
Moritz Warning Wrote:On Sun, 13 Jul 2008 03:38:36 +0200, Oliver Dathe wrote:I had this problem some months ago and found a solution: You can extract the information, whether a function given as a template alias parameter is static or not, from the mangle of it. Currently, I'm developing a Compile-Time-Function-Execution- and Template-Metaprogramming- Utils library. The first goal after some string-parsing routines is a compile-time demangler which will then also be able to extract this information. But I guess, I'll stillt need some weeks for this. When I'm done, I'll create a dsource projects and announce it on the news. best regards Matthias WalterThis works here: template isCallableStatically(T) { static if (is(T==function) || is(typeof(*T)==function)) const bool isCallableStatically = true; else static if (is(T==delegate)) const bool isCallableStatically = false; else static assert (false); } template isCallableStatically(alias T) { const isCallableStatically = isCallableStatically!(typeof(&T)); } void fn() {} void main() { void dg() {} static assert (isCallableStatically!(fn)); static assert (!isCallableStatically!(dg)); static assert (isCallableStatically!(typeof(&fn))); static assert (!isCallableStatically!(typeof(&dg))); }Doesn't work for A.bar and A.foo (where foo is static and therefore don't need an object)
Jul 13 2008
On Sun, 13 Jul 2008 09:42:59 -0400, Matthias Walter wrote:Moritz Warning Wrote:Great! I'm looking forward to make use of the solution.On Sun, 13 Jul 2008 03:38:36 +0200, Oliver Dathe wrote:I had this problem some months ago and found a solution: You can extract the information, whether a function given as a template alias parameter is static or not, from the mangle of it. Currently, I'm developing a Compile-Time-Function-Execution- and Template-Metaprogramming- Utils library. The first goal after some string-parsing routines is a compile-time demangler which will then also be able to extract this information. But I guess, I'll stillt need some weeks for this. When I'm done, I'll create a dsource projects and announce it on the news. best regards Matthias WalterThis works here: template isCallableStatically(T) { static if (is(T==function) || is(typeof(*T)==function)) const bool isCallableStatically = true; else static if (is(T==delegate)) const bool isCallableStatically = false; else static assert (false); } template isCallableStatically(alias T) { const isCallableStatically = isCallableStatically!(typeof(&T)); } void fn() {} void main() { void dg() {} static assert (isCallableStatically!(fn)); static assert (!isCallableStatically!(dg)); static assert (isCallableStatically!(typeof(&fn))); static assert (!isCallableStatically!(typeof(&dg))); }Doesn't work for A.bar and A.foo (where foo is static and therefore don't need an object)
Jul 14 2008