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. Advertisements

  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. Advertisements

  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. Advertisements

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. newbiecpp

    run-time vs compile-time

    newbiecpp, Sep 8, 2004, in forum: C++
    Replies:
    17
    Views:
    6,856
    Chris \( Val \)
    Sep 11, 2004
  2. Daniel T.
    Replies:
    2
    Views:
    466
    Daniel T.
    Oct 19, 2004
  3. Markus Dehmann

    compile time vs. run time?

    Markus Dehmann, Jan 22, 2005, in forum: C++
    Replies:
    11
    Views:
    820
    Joseph Turian
    Jan 24, 2005
  4. Samee Zahur
    Replies:
    1
    Views:
    4,386
    Jerry Coffin
    Apr 17, 2005
  5. flamesrock
    Replies:
    8
    Views:
    807
    Hendrik van Rooyen
    Nov 24, 2006
  6. Nagaraj
    Replies:
    1
    Views:
    1,192
    Lionel B
    Mar 1, 2007
  7. Generic Usenet Account
    Replies:
    10
    Views:
    2,940
  8. Carter
    Replies:
    2
    Views:
    682
    Carter
    Mar 4, 2009
Loading...