Template parameter default help

Chris Nicholson-Sauls ibisbasenji at gmail.com
Sat Sep 30 19:43:26 PDT 2006



Chad J > wrote:
> struct Type1(ulong blah, ulong distinction = 0)
> {
>     float member;
> }
> 
> struct Type2(ulong distinction = 0)
> {
>     float member;
> }
> 
> void main()
> {
>     // I can do this...
>     Type1!(0) test1;
>     Type1!(0,2) test2;
> 
>     // but not this?
>     Type2 test3;
>     Type2!(2) test4;
> }
> 
> 
> I also tried this:
> 
> struct Type3(ulong distinction)
> {
>     float member;
> }
> alias Type3!( 0 ) Type3; // Type3!( 0 ) conflicts with Type3? argh!
> 
> 
> Is there any way I can make that sort of shorthand in Type2 work?

Yes and no.  The exact way you are trying, just won't work.  However, if you instantiate 
this template with no parameters (Type2!()) it will work.  The aliasing trick used to 
work; I think it was (inadvertantly?) canceled when IFTI support was added.

-- Chris Nicholson-Sauls



More information about the Digitalmars-d-learn mailing list