Static CT Factory

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 18 19:54:48 PDT 2016


On Friday, 19 August 2016 at 01:53:22 UTC, Engine Machine wrote:
> On Friday, 19 August 2016 at 01:25:10 UTC, Anonymouse wrote:
>> On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine
>>> x = 1.234;
> Ok, well, I guess the error comes from something else.

*x = 1.234 for when T verifies is(T == int*) produces an error.

You can put an aditional argument in the function header:

void foo(T)(auto ref T t = T.init)
{
	static if (is(T == int))
	    auto x = new Thing!int;
	else static if (is(T == double))
	    auto x = new Thing!double;
	else
             static assert(false, "incorrect type");
	*x = t;
}


More information about the Digitalmars-d-learn mailing list