Thread overview
Template problem
Mar 09, 2005
David Medlock
Mar 09, 2005
xs0
Mar 09, 2005
David Medlock
Mar 09, 2005
xs0
March 09, 2005
import std.stdio;
template Test( C : char )
{
  void print()
  {
    writefln( C );
  }
}

void main( char[][] arg )
{
  Test!('a').print();
}

---------- Capture Output ----------
> "C:\dmd\bin\dmd.exe" -debug -c C:\proj\temp\test.d
C:\proj\temp\test.d(16): template instance Test!(97) does not match any template declaration
C:\proj\temp\test.d(16): undefined identifier template instance Test!(97).print
C:\proj\temp\test.d(16): function expected before (), not 'void'


Anyone see what is wrong here?
March 09, 2005
David Medlock wrote:
> 
> import std.stdio;
> template Test( C : char )
> {
>   void print()
>   {
>     writefln( C );
>   }
> }
> 
> void main( char[][] arg )
> {
>   Test!('a').print();
> }
> 
> ---------- Capture Output ----------
>  > "C:\dmd\bin\dmd.exe" -debug -c C:\proj\temp\test.d
> C:\proj\temp\test.d(16): template instance Test!(97) does not match any template declaration
> C:\proj\temp\test.d(16): undefined identifier template instance Test!(97).print
> C:\proj\temp\test.d(16): function expected before (), not 'void'
> 
> 
> Anyone see what is wrong here?

It should be "char C" instead of "C : char"...


xs0
March 09, 2005
xs0 wrote:

> David Medlock wrote:

>> Anyone see what is wrong here?
> 
> 
> It should be "char C" instead of "C : char"...
> 
> 
> xs0

Thanks.

Don't know why I thought the : syntax was specialization....

What really threw me off is if you make it

template Test( C )

it still fails, which is kind of weird, as there is no other Test template....
March 09, 2005
> Don't know why I thought the : syntax was specialization....
> 
> What really threw me off is if you make it
> 
> template Test( C )
> 
> it still fails, which is kind of weird, as there is no other Test template....

C matches types
char C matches actual chars (values)
C : Type matches Type or its derivative (or maybe just Type, not sure)
C : char matches just type char (not a char value or even char typedef)
char C : 'a' matches the character 'a'


xs0