Detecting the arity of a constructor at compile time

  • Thread starter Michael Feathers
  • Start date
M

Michael Feathers

I was wondering if it is at all possible to detect the arity of
constructors at compile time using some combination of macros and
template metaprogramming. I'd like to be able to determine whether
a class has, for instance, a constructor with two arguments or a
constructor with three arguments. Is there any way to do this?

Michael
 
V

Victor Bazarov

Michael said:
I was wondering if it is at all possible to detect the arity of
constructors at compile time using some combination of macros and
template metaprogramming. I'd like to be able to determine whether
a class has, for instance, a constructor with two arguments or a
constructor with three arguments. Is there any way to do this?

I'd like to educate myself in this matter. Could you explain why you
want to do that?

Many thanks!

V
 
M

Michael Feathers

Victor said:
I'd like to educate myself in this matter. Could you explain why you
want to do that?

Many thanks!

V


I'd like to write a dependency injection framework that doesn't place
many constraints on the types it manages. I suspect that it would
be easier to use setter-based injection and something like
Alexandrescu's GenLinearHierarchy, but I was wondering if there is
a way to do constructor injection.

Michael Feathers
www.objectmentor.com
 
R

Roland Pibinger

I'd like to write a dependency injection framework that doesn't place
many constraints on the types it manages. I suspect that it would
be easier to use setter-based injection and something like
Alexandrescu's GenLinearHierarchy, but I was wondering if there is
a way to do constructor injection.

In Java DI is usually implemented with interfaces. You do them same in
C++ with abstract base classes. WRT the 'arity of constructors' have
you considered default arguments?

Best regards,
Roland Pibinger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top