Getting the parameters of a struct/class constructor

Philippe Sigaud philippe.sigaud at gmail.com
Thu Jan 24 14:30:03 PST 2013


On Thu, Jan 24, 2013 at 10:34 PM, Rob T <alanb at ucora.com> wrote:
> On Thursday, 24 January 2013 at 18:41:31 UTC, mist wrote:
>>
>> You can use "magic" functions __ctor and __dtor which actually serve as
>> constructor and destructor implementations behind the scene.
>>
>> Example and proof-of-concept: http://dpaste.1azy.net/fd924332
>>
>> Have no idea if it is explicitly defined by spec somewhere though.
>
>
> If you have more than one ctor it seems to take the first one
>
> http://dpaste.1azy.net/b994fdf3
>
> I don't know if you will able to rely on the order unless it's a part of the
> spec.

IIRC, you can use __traits(getOverloads, mytype.__ctor) to get all
constructor overloads.
See:
http://dlang.org/traits.html#getOverloads

I used this in conjunction with __traits(getMember, ...) to get the
entire list of member, overloads included.


More information about the Digitalmars-d-learn mailing list