@tag: BiT [[C]] TemplatE CPlusPlus
==== C ====
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
#define TYPE_MAX(t) \
((t) (! TYPE_SIGNED (t) \
? (t) -1 \
: ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
==== CPlusPlus ====
#include
#include
#include
template
T max()
{
T Value = ~0;
if (Value == (Value >> 1)) {
Value = 1;
Value <<= (sizeof(Value) << 3) - 1;
Value = ~Value;
}
return(Value);
}
info: unsigned short (16b) [0,65535]
info: unsigned int (32b) [0,4294967295]
info: unsigned long (32b) [0,4294967295]
info: unsigned long long (64b) [0,18446744073709551615]
info: short (16b) [-32768,32767]
info: int (32b) [-2147483648,2147483647]
info: long (32b) [-2147483648,2147483647]
info: long long (64b) [-9223372036854775808,9223372036854775807]
template
T min()
{
T Value = max();
return(++Value);
}
template
void display()
{
std::string name;
int status;
name = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
std::cout << "info: " << name << " ("<<(sizeof(T)<<3)<<"b)"<<" [" << min() <<","<< max() <<"]"<();
display();
display();
display();
display();
//display();
//display();
//display();
display();
display();
display();
display();
//display();
//display();
return(0);
}
/*
info: unsigned short (16b) [0,65535]
info: unsigned int (32b) [0,4294967295]
info: unsigned long (32b) [0,4294967295]
info: unsigned long long (64b) [0,18446744073709551615]
info: short (16b) [-32768,32767]
info: int (32b) [-2147483648,2147483647]
info: long (32b) [-2147483648,2147483647]
info: long long (64b) [-9223372036854775808,9223372036854775807]
*/