www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Type tuple of all constructors?

reply Benjamin Thaut <code benjamin-thaut.de> writes:
Is there a way to get a type tuple of all aviable constructors in a class?

class Test {
   public:
     this(Foo foo){
       m_foo = foo;
     }

     this(bool flop){
     }

     this(int x, int y){
     }
}

For this class I would expect something like ((Foo),(bool),(int,int))
-- 
Kind Regards
Benjamin Thaut
Sep 22 2011
parent Jakob Ovrum <jakobovrum+ng gmail.com> writes:
On 2011/09/23 1:11, Benjamin Thaut wrote:
 Is there a way to get a type tuple of all aviable constructors in a class?

 class Test {
 public:
 this(Foo foo){
 m_foo = foo;
 }

 this(bool flop){
 }

 this(int x, int y){
 }
 }

 For this class I would expect something like ((Foo),(bool),(int,int))

$ cat test.d struct Foo {} class Test { public: this(Foo foo){ } this(bool flop){ } this(int x, int y){ } } import std.traits; import std.stdio; void main() { foreach(ctor; __traits(getOverloads, Test, "__ctor")) { alias ParameterTypeTuple!(typeof(ctor)) args; writeln(args.stringof); } } $ ./test (Foo) (bool) (int, int)
Sep 22 2011