On 1/24/13, Andrej Mitrovic <andrej.mitrov...@gmail.com> wrote:
> On 1/24/13, Joseph Rushton Wakeling <joseph.wakel...@webdrake.net> wrote:
>>      ParameterTypeTuple!(A.this)
>
> Use ParameterTypeTuple!(A.__ctor)
>

If you have multiple constructors you can pick the parameters with a
helper template:

import std.traits, std.string;

struct A
{
        this(int a, double b)
        {
        }

    this(float y)
    {
    }
}

template PickCtorParams(Type, size_t index)
{
    enum ctorLen = __traits(getOverloads, Type, "__ctor").length;
    static if (index < ctorLen)
    {
        alias ParameterTypeTuple!(__traits(getOverloads, A,
"__ctor")[index]) PickCtorParams;
    }
    else
    {
        static assert(0,
            format("index %s exceeds %s ctors for type %s", index,
ctorLen, Type.stringof));
    }
}

void main()
{
    pragma(msg, PickCtorParams!(A, 0));  // (int, double)
    pragma(msg, PickCtorParams!(A, 1));  // (float)
    pragma(msg, PickCtorParams!(A, 2));  // out of bounds
}

Reply via email to