Static CT Factory
    Anonymouse via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Thu Aug 18 18:25:10 PDT 2016
    
    
  
On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine wrote:
> I have a template that is suppose to create a type based on a 
> template parameter
>
> static if (T == "int")
> {
>    auto x = New!int();
> }
> else static if (T == "double")
> {
>    auto x = New!double();
> }
>
> x = 1.234;
>
>
> This is just an example, I use custom types.
>
> The static if's prevent x's scope from being after them, even 
> though it should work perfectly fine. I can't declare x before 
> because I don't know the type.
I'm not sure I understand. static if shouldn't introduce a new 
scope that way.
https://dpaste.dzfl.pl/7b63a6e52309
Mind that x might be a pointer.
    
    
More information about the Digitalmars-d-learn
mailing list