Global template specialization in namespace -- alternative?

A

Alf P. Steinbach

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 }; };
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top