Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Global template specialization in namespace -- alternative?

Thread Tools

Global template specialization in namespace -- alternative?

Alf P. Steinbach
Posts: n/a
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:ersonKindEnum>
{ 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?
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Full specialization of a member function template of a class template Dave C++ 4 06-04-2010 12:15 PM
Template specialization doesn't work after putting inside a namespace C++ 6 12-17-2008 08:17 AM
template specialization overriding non-specialization? Joseph Turian C++ 2 04-16-2006 02:46 PM
template specialization of a template class pit3k C++ 8 02-09-2005 02:39 AM
Specialization of a template within template David B. Held C++ 2 10-26-2003 11:59 AM