How to distinguish a delegate from a function?
Matthias Walter
Matthias.Walter at st.ovgu.de
Sun Jul 13 06:42:59 PDT 2008
Moritz Warning Wrote:
> 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)
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 Walter
More information about the Digitalmars-d
mailing list