Template for function or delegate (nothing else)

Steven Schveighoffer schveiguy at yahoo.com
Thu Feb 10 08:05:39 PST 2011


On Thu, 10 Feb 2011 09:48:14 -0500, useo <useo at start.bg> wrote:


> I created a complete, new file with the following code:
>
> module example;
>
> void main(string[] args) {
> 	Example!(void function()) myVar;
> }
>
> class Example(T) if (is(T == delegate) || is(T == function)) {
> }
>
> And what I get is:
>
> example.d(4): Error: template instance Example!(void function()) does
> not match template declaration Example(T) if (is(T == delegate) || is
> (T == function))
> example.d(4): Error: Example!(void function()) is used as a type
>
> I'm using the current stable version 2.051.

Found this invalid bug.  Apparently, this is expected (!) behavior:

http://d.puremagic.com/issues/show_bug.cgi?id=3464

So use this instead:

class Example(T) if (is(T == delegate) || is(typeof(*T.init) == function))

Ugly, I know, but I guess that's what we got to work with.

-Steve


More information about the Digitalmars-d-learn mailing list