Logo

Programming-Idioms

History of Idiom 73 > diff from v308 to v309

Edit summary for version 309 by :

Version 308

2015-10-29, 13:38:24

Version 309

2015-10-29, 14:05:16

Idiom #73 htVgBtlcWttUPGOu

Have you got any ? <a href=" http://www.cimoszewicz.eu/?list-erectile-dysfunction-drugs-noida.pptx ">erectile dysfunction price comparison writing</a> Dustin Johnson certainly has the game to win a major title. Hunter Mahan has been a perennial contender in the big events. Maybe Lee Westwood will finally break through after coming close again at the British Open.

Idiom #73 Create a factory

Create a factory named pFact for any sub class of Parent and taking exactly one string str as constructor parameter.

Code
auto pFact(T, A...)(A a)
if (is(T==class) && is(T: Parent))
{
    return new T(a);
}
Code
auto pFact(T, A...)(A a)
if (is(T==class) && is(T: Parent))
{
    return new T(a);
}
Comments bubble
In D we can cover all the possible constructors using a variadic argument. Parent is checked statically with a constraint.
Comments bubble
In D we can cover all the possible constructors using a variadic argument. Parent is checked statically with a constraint.
Demo URL
http://dpaste.dzfl.pl/9d4241e06f9e
Demo URL
http://dpaste.dzfl.pl/9d4241e06f9e