Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Detecting the arity of a constructor at compile time

Reply
Thread Tools

Detecting the arity of a constructor at compile time

 
 
Michael Feathers
Guest
Posts: n/a
 
      08-04-2006

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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-04-2006
Michael Feathers wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Michael Feathers
Guest
Posts: n/a
 
      08-04-2006
Victor Bazarov wrote:
> Michael Feathers wrote:
>
>>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



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

 
Reply With Quote
 
Roland Pibinger
Guest
Posts: n/a
 
      08-04-2006
On Fri, 04 Aug 2006 13:43:14 GMT, Michael Feathers
<(E-Mail Removed)> wrote:

>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why the expression "(1)" is not an one-arity tuple, but int ? Петров Александр Python 0 12-04-2009 12:17 PM
computation at compile time i.e. compile time functions usingtemplates Carter C++ 2 03-04-2009 06:43 PM
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
overloading on the template parameter arity of a template templateparameter Howard Gardner C++ 4 07-19-2006 11:10 PM



Advertisments