D
Dominic Connor, Pimp
I've got a bit of code that shows which bits of a variable are 1 or 0
(OK, I'm making assumptions about 8 bit bytes and significance.)
But what I want to do is only allow this template to be instantiated
for base types, not classes.
I am averse to RTTI for this, but I keep thinking there's a bit of
syntactic sugar that will do it cleanly.
Solutions of the form "classes are bigger than 64 bits so reject them"
don't count
template <typename T> string DumpBits (T x)
{
unsigned int mask=1;
int i;
string s;
for ( i= 0; i != sizeof(x)*8; i++, mask *=2)
{
mask & x ? s = "1" + s : s = "0" + s;
}
return s;
}
(OK, I'm making assumptions about 8 bit bytes and significance.)
But what I want to do is only allow this template to be instantiated
for base types, not classes.
I am averse to RTTI for this, but I keep thinking there's a bit of
syntactic sugar that will do it cleanly.
Solutions of the form "classes are bigger than 64 bits so reject them"
don't count
template <typename T> string DumpBits (T x)
{
unsigned int mask=1;
int i;
string s;
for ( i= 0; i != sizeof(x)*8; i++, mask *=2)
{
mask & x ? s = "1" + s : s = "0" + s;
}
return s;
}