digitalmars.D.learn - Template parameter default help
- Chad J (24/24) Sep 30 2006 struct Type1(ulong blah, ulong distinction = 0)
- Chris Nicholson-Sauls (5/37) Sep 30 2006 Yes and no. The exact way you are trying, just won't work. However, if...
- Chad J (5/12) Sep 30 2006 This is kinda unfortunate. I wanted to make a struct where, in most
- Chris Nicholson-Sauls (5/21) Oct 01 2006 While it isn't "pretty" you could rename the template-struct to Type2T o...
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?
Sep 30 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
Sep 30 2006
Chris Nicholson-Sauls wrote: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-SaulsThis is kinda unfortunate. I wanted to make a struct where, in most cases, someone would not need knowledge of template syntax to use it. Type2!() doesn't accomplish that :( Anyhow, thanks for the info Chris!
Sep 30 2006
Chad J > wrote:Chris Nicholson-Sauls wrote:While it isn't "pretty" you could rename the template-struct to Type2T or TType2 and alias it from that ('alias Type2T!() Type2;')... still not perfect of course. I do miss the old aliasing trick. Le sigh. -- Chris Nicholson-SaulsYes 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-SaulsThis is kinda unfortunate. I wanted to make a struct where, in most cases, someone would not need knowledge of template syntax to use it. Type2!() doesn't accomplish that :( Anyhow, thanks for the info Chris!
Oct 01 2006