Re: Templated Struct Constructor

2011-12-12 Thread Steven Schveighoffer
On Sat, 10 Dec 2011 02:42:30 -0500, Andrew Wiley wrote: On Sat, Dec 10, 2011 at 1:23 AM, Andrew Wiley wrote: Is there a syntax that allows me to specify arguments to a templated constructor for a struct? The intuitive way looks like this, but it doesn't work. --- struct Test { this

Re: Templated Struct Constructor

2011-12-10 Thread Andrej Mitrovic
You can cheat with __ctor: Test test = Test.__ctor!(int, true)(5);

Re: Templated Struct Constructor

2011-12-10 Thread Andrew Wiley
On Sat, Dec 10, 2011 at 5:38 AM, Trass3r wrote: >> Looks like I can work around it by doing this: >> --- >> template makeTest(T, bool b) { >>    static if((b && something) || (!b && somethingElse)) { >>        alias Test makeTest; >>    } >>    else static assert(0, "some error message"); >> } >>

Re: Templated Struct Constructor

2011-12-10 Thread Trass3r
Looks like I can work around it by doing this: --- template makeTest(T, bool b) { static if((b && something) || (!b && somethingElse)) { alias Test makeTest; } else static assert(0, "some error message"); } struct Test { private: this(T)(T info) { } } void main() {

Re: Templated Struct Constructor

2011-12-09 Thread Andrew Wiley
On Sat, Dec 10, 2011 at 1:23 AM, Andrew Wiley wrote: > Is there a syntax that allows me to specify arguments to a templated > constructor for a struct? The intuitive way looks like this, but it > doesn't work. > > --- > struct Test { >        this(T, bool b)(T info) if((b && something ) || (!b &&

Templated Struct Constructor

2011-12-09 Thread Andrew Wiley
Is there a syntax that allows me to specify arguments to a templated constructor for a struct? The intuitive way looks like this, but it doesn't work. --- struct Test { this(T, bool b)(T info) if((b && something ) || (!b && somethingElse)) { } } void main() {