Function pointer argument to function template
Kirk McDonald
kirklin.mcdonald at gmail.com
Tue May 30 16:52:42 PDT 2006
Ah! The IsExpression! I hadn't remembered that at all from when I read
the spec. This will do nicely, thanks!
-Kirk McDonald
Tom S wrote:
> Hey there :)
>
> I came up with this:
>
> ----
>
> import std.stdio;
>
> template Deref(T) {
> alias typeof(*T) Deref;
> }
>
> template RetType(T) {
> static if (is(Deref!(T) U == function)) {
> alias U RetType;
> } else static assert (false);
> }
>
> template Bar(T, U=RetType!(T)) {
> U Bar(T t) {
> writefln(typeid(U));
>
> // do something :P
> return U.init;
> }
> }
>
>
> cfloat func(int a, float b) {
> return 1.f + 0i;
> }
>
>
> void main() {
> writefln(Bar(&func));
> }
>
>
> --
> Tomasz Stachowiak /+ a.k.a. h3r3tic +/
More information about the Digitalmars-d
mailing list