Template for function or delegate (nothing else)

useo useo at start.bg
Thu Feb 10 07:11:38 PST 2011


== Auszug aus useo (useo at start.bg)'s Artikel
> == Auszug aus Steven Schveighoffer (schveiguy at yahoo.com)'s Artikel
> > On Thu, 10 Feb 2011 09:09:03 -0500, useo <useo at start.bg> wrote:
> > > I implemented all I wanted and it works perfectly ;).
> > >
> > > But I'm using the "if (is(T == delegate) || is(T == function))"-
> > > statement in another class/template.
> > >
> > > class Example(T) if (is(T == delegate) || is(T == function)) {
> > > ...
> > > }
> > >
> > > Now, when I declare Example!(void function()) myVar; I always
get:
> > >
> > > Error: template instance Example!(void function()) does not
match
> > > template declaration Example(T) if (is(T == delegate) || is(T ==
> > > function))
> > > Error: Example!(void function()) is used as a type
> > >
> > > When I declare myVar as Example!(function), I get some other
> errors.
> > >
> > > What's wrong with my code?
> > Please post a full example that creates the error.  From that
error
> > message, it appears that your code is correct, but I'd have to
play
> with a
> > real example to be sure.
> > -Steve
> 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.

I noticed, that this error only occurs when I use function as
template-type. When I use Example!(void delegate()) myVar; it
compiles without any error. With function - Example!(void function())
myVar; I get the error(s) above.


More information about the Digitalmars-d-learn mailing list