I have been trying to go through the Boost type-traits headers, and feeling quite sick now given the intense unreadability provided by countless #define. And then some more #define.
To be specific, I am interested in figuring out about the following 3 traits: if a type T is an array, a class or an enum.
Can anyone help suggest some way of deciphering the method behind the apparent madness? Like the theory behind how you figure out the trait from a type, any relevant reading material etc.
is_array
is pretty simple and straight forward:
template<class T>
struct is_array{
static const bool value = false;
};
template<class T, std::size_t N>
struct is_array< T (&)[N] >{
static const bool value = true;
};
Just a simple partial specialization on a reference-to-array type.
is_class
is a bit more complicated and relies on overload resolution and the fact, that classes and struct possess constructors (or destructors). As I'm currently on my iPod Touch, I can't really show an example. I'll edit one in as soon as I've access to a PC again.
is_enum
relies on compiler intrinsics I believe, so no example there.
Note: Everything here is from memory, I could be wrong with the enum one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With