1 2 module witchcraft.constructors; 3 4 import witchcraft; 5 6 import std.string; 7 import std.variant; 8 9 /++ 10 + Represents and grants access to a single constructor defined in some 11 + aggregate type. 12 ++/ 13 abstract class Constructor : Invocable 14 { 15 /++ 16 + Invokes the constructor, passing in arguments as variant types. 17 + The result is returned as a `Variant` type. 18 + 19 + Returns: 20 + The result of the construct call, as a `Variant`. 21 ++/ 22 final Variant create(Variant[] arguments...) const 23 { 24 return this.invoke(null, arguments); 25 } 26 27 /++ 28 + Ditto, but accepts arguments of any type, and permits the result to also 29 + be cast to a type specified by template argument. 30 + 31 + Params: 32 + T = The conversion type. If Variant, no conversion is performed. 33 + 34 + Returns: 35 + The result of the construct call, as the templated type. 36 ++/ 37 final T create(T, TList...)(TList arguments) const 38 { 39 auto result = this.invoke(null, arguments); 40 41 static if(is(T == Variant)) 42 { 43 return result; 44 } 45 else 46 { 47 return result.get!T; 48 } 49 } 50 51 /++ 52 + Returns `__ctor`, which is the name of all constructors. 53 + 54 + Returns: 55 + The name of this constructor. 56 ++/ 57 final override string getName() const 58 { 59 return "__ctor"; 60 } 61 62 override string toString() const 63 { 64 return "%s(%(%s, %))".format(getName, getParameterTypeInfos); 65 } 66 }