Class type at compile time

Discussion in 'C++' started by Christopher Benson-Manica, Aug 18, 2004.

  1. I know there's a way to determine whether a given class is a
    member of a given class hierarchy at compile time, but I'll be darned
    if I can find it again. Can someone help? Thanks...

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Aug 18, 2004
    #1
    1. Advertising

  2. Christopher Benson-Manica

    Kai-Uwe Bux Guest

    Christopher Benson-Manica wrote:

    > I know there's a way to determine whether a given class is a
    > member of a given class hierarchy at compile time, but I'll be darned
    > if I can find it again. Can someone help? Thanks...
    >


    Recommendation: use Boost.

    #include <boost/type_traits.hpp>

    boost::is_base_and_derived<T,U>::value

    is true if U derives from T and false otherwise.)



    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Aug 18, 2004
    #2
    1. Advertising

  3. Jonathan Turkanis <> spoke thus:

    > Perhaps you're looking for boost::is_base_and_derived<Base, Derived> ?


    Yes, that was it. Unfortunately, I can't use boost, but at some point
    I implemented it myself. Too bad I can't find that code anymore ;(
    Anyway, thanks.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Aug 18, 2004
    #3
  4. "Christopher Benson-Manica" <> wrote in
    message news:cg0alv$grr$...
    > I know there's a way to determine whether a given class is a
    > member of a given class hierarchy at compile time, but I'll be

    darned
    > if I can find it again. Can someone help? Thanks...


    Perhaps you're looking for boost::is_base_and_derived<Base, Derived> ?

    Jonathan
    Jonathan Turkanis, Aug 18, 2004
    #4
  5. Jonathan Turkanis <> spoke thus:

    > Perhaps you're looking for boost::is_base_and_derived<Base, Derived> ?


    I also was positive that I originally saw this in Stroustrup's Style
    and Technique FAQ, but it doesn't seem to be there now. Am I just
    crazy, or is there an underlying reason why I might have had such a
    delusion?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Aug 18, 2004
    #5
  6. "Christopher Benson-Manica" <> wrote in
    message news:cg0cd9$h12$...
    > Jonathan Turkanis <> spoke thus:
    >
    > > Perhaps you're looking for boost::is_base_and_derived<Base,

    Derived> ?
    >
    > I also was positive that I originally saw this in Stroustrup's Style
    > and Technique FAQ, but it doesn't seem to be there now. Am I just
    > crazy, or is there an underlying reason why I might have had such a
    > delusion?


    Isn't being crazy a good reason for a delusion? ;-)

    I don't have time to check Stroustrup's site now, but my recollection
    was that most of his techniques were related to producing compiler
    errors if a type doesn't conform to a concept.

    Anyway, you should be able to use a modified version of the boost
    implementation, which is fairly self-contained. If you don't have to
    worry about ambiguous and private bases you should be able to simplify
    it considerably.

    Jonathan
    Jonathan Turkanis, Aug 18, 2004
    #6
    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. A
    Replies:
    1
    Views:
    552
    Josephine Schafer
    Oct 22, 2003
  2. newbiecpp

    run-time vs compile-time

    newbiecpp, Sep 8, 2004, in forum: C++
    Replies:
    17
    Views:
    6,600
    Chris \( Val \)
    Sep 11, 2004
  3. flamesrock
    Replies:
    8
    Views:
    430
    Hendrik van Rooyen
    Nov 24, 2006
  4. Nagaraj
    Replies:
    1
    Views:
    823
    Lionel B
    Mar 1, 2007
  5. Carter
    Replies:
    2
    Views:
    485
    Carter
    Mar 4, 2009
Loading...

Share This Page