Jiggy-Ninja:
There’s a ton more stuff in there, some of it really clever using inheritance from helper classes and partial specialization.
Like is_const (going from memory):
template<class T>
struct is_const
{
static const bool value = false;
};
template
struct is_const
{
static const bool value = true;
};
I've attached the type_traits header that came with my desktop C++ IDE. You'll see that I've simplified their implementation quite a bit in porting it.
[Check it all out.](http://www.cplusplus.com/reference/type_traits/)
OK, I looked at it and honestly didn’t understand how to use it. Also, I would like (although not absolutely necessary) for it to work in C and C++.
Anyway, an idea popped into my head, I tried it and it seemed to work. Then I expanded the test and it didn’t work reliably. See what you think and why it “sort-of” works, but not all of it:
First of all, I tried this macro: [b]#define IS_SIGNED(T)(T=-1,T==-1?1:0)[/b]
#define IS_SIGNED(T)(T=-1,T==-1?1:0)
int main (void)
{
char buffer [64];
uint8_t u8;
int8_t s8;
uint16_t u16;
int16_t s16;
signed int si;
unsigned int ui;
init();
Serial.begin (115200);
sprintf (buffer, "u8 is %s\n", IS_SIGNED (u8) ? "signed" : "unsigned");
Serial.print (buffer);
sprintf (buffer, "s8 is %s\n", IS_SIGNED (s8) ? "signed" : "unsigned");
Serial.print (buffer);
sprintf (buffer, "u16 is %s\n", IS_SIGNED (u16) ? "signed" : "unsigned");
Serial.print (buffer);
sprintf (buffer, "s16 is %s\n", IS_SIGNED (s16) ? "signed" : "unsigned");
Serial.print (buffer);
sprintf (buffer, "si is %s\n", IS_SIGNED (si) ? "signed" : "unsigned");
Serial.print (buffer);
sprintf (buffer, "ui is %s\n", IS_SIGNED (ui) ? "signed" : "unsigned");
Serial.print (buffer);
while (1);
}
And this is what it outputs:
[b]u8 is unsigned
s8 is signed
[color=red]u16 is signed[/color]
s16 is signed
si is signed
[color=red]ui is signed[/color][/b]
The ones I highlighted in red are wrong!!! Why on earth would uint8_t work but the other unsigned ones fail? ARGHHHHHH!!!