Templated Struct Constructor
    Trass3r 
    un at known.com
       
    Sat Dec 10 03:38:14 PST 2011
    
    
  
> 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() {
>     Test test = Test!(int, true)(5); // Error: template instance
>     Test!(int,true) Test is not a template declaration, it is a struct
> }
> ---
>
> But this solution isn't very satisfying because Test is no longer
> directly protected by the static checks I want.
Shouldn't this work too:
struct Test(T, bool b)
if((b && something ) || (!b && somethingElse))
{
	this(T info)
	{
	}
}
It's still a bug imho though.
    
    
More information about the Digitalmars-d
mailing list