Detecting the arity of a constructor at compile time

Discussion in 'C++' started by Michael Feathers, Aug 4, 2006.

  1. 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
     
    Michael Feathers, Aug 4, 2006
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Aug 4, 2006
    #2
    1. Advertising

  3. 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
     
    Michael Feathers, Aug 4, 2006
    #3
  4. On Fri, 04 Aug 2006 13:43:14 GMT, Michael Feathers
    <> 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
     
    Roland Pibinger, Aug 4, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Howard Gardner
    Replies:
    4
    Views:
    357
    Howard Gardner
    Jul 20, 2006
  2. Nagaraj
    Replies:
    1
    Views:
    883
    Lionel B
    Mar 1, 2007
  3. Generic Usenet Account
    Replies:
    10
    Views:
    2,253
  4. Carter
    Replies:
    2
    Views:
    512
    Carter
    Mar 4, 2009
  5. ðÅÔÒÏ× áÌÅËÓÁÎÄÒ

    Why the expression "(1)" is not an one-arity tuple, but int ?

    ðÅÔÒÏ× áÌÅËÓÁÎÄÒ, Dec 4, 2009, in forum: Python
    Replies:
    0
    Views:
    275
    ðÅÔÒÏ× áÌÅËÓÁÎÄÒ
    Dec 4, 2009
Loading...

Share This Page