Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost type_traits is_array

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.

like image 676
Fanatic23 Avatar asked Oct 10 '22 22:10

Fanatic23


1 Answers

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.

like image 188
Xeo Avatar answered Oct 26 '22 22:10

Xeo