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

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top