templates question
I put together the following little template meta-foolishness in order
to quiet some compiler warning about "pointless comparison of unsigned
integer with zero" for various unsigned types. As you can see, I made
separate template parameters for isSigned and isSpecialized (since the
unspecialized value of is_signed is false).
Now I'm just wondering if it's permitted to combine these as a single
parameter, say isSpecializedAndUnsigned, and in the definition of
NONNEGATIVE write something like:
return NonNegativeCore<T,std::numeric_limits<T>::is_specialized &
!std::numeric_limits<T>::is_signed>;
In other words, can I always rely upon the compiler to do the simple
boolean algebra above (it works for me with gcc)? And more generally,
what sorts of expressions will the compiler evaluate in this situation?
Thanks,
Mark
// code sinppet
template <typename T, bool isSigned, bool isSpecialized>
struct NonNegativeCore
{
static bool isIt (T x) {return x >= 0;}
};
template <typename T>
struct NonNegativeCore<T,false,true>
{
static bool isIt (T x) {return true;}
};
template <typename T>
inline bool NONNEGATIVE (T x)
{
return NonNegativeCore<T,std::numeric_limits<T>::is_signed,
std::numeric_limits<T>::is_specialized>::isIt(x);
}