Global template specialization in namespace -- alternative?

Discussion in 'C++' started by Alf P. Steinbach, Oct 10, 2005.

  1. Is there any way to get the "enabling" traits definitions textually closer to
    (ideally on the line below) the enums they refer to, in the code below?


    template< bool shouldBeTrue > struct StaticAssert_;
    template<> struct StaticAssert_<true> {};

    template< typename T >
    struct EnumIncrementEnabled_{ enum{ yes = false }; };

    template< typename T >
    inline T operator++( T& v )
    {
    StaticAssert_< EnumIncrementEnabled_<T>::yes >();
    v = T( v + 1 ); return v;
    }

    namespace nac_puzzle
    {
    enum RiverSideEnum{ left, right };
    inline RiverSideEnum opposite( RiverSideEnum side )
    {
    return RiverSideEnum( 1 - side );
    }

    enum PersonKindEnum{ cannibal, nun };
    inline PersonKindEnum opposite( PersonKindEnum kind )
    {
    return PersonKindEnum( 1 - kind );
    }

    enum { nPersonsOfAKind = 3, maxPerTransfer = 2 };
    }
    template<> struct EnumIncrementEnabled_<nac_puzzle::RiverSideEnum>
    { enum{ yes = true }; };
    template<> struct EnumIncrementEnabled_<nac_puzzle::personKindEnum>
    { enum{ yes = true }; };

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Oct 10, 2005
    #1
    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. David B. Held
    Replies:
    2
    Views:
    466
    Rob Williscroft
    Oct 26, 2003
  2. Dave
    Replies:
    4
    Views:
    7,664
    pdixtl
    Jun 4, 2010
  3. pit3k
    Replies:
    8
    Views:
    366
    Victor Bazarov
    Feb 9, 2005
  4. Joseph Turian
    Replies:
    2
    Views:
    463
  5. Replies:
    6
    Views:
    3,856
Loading...

Share This Page