dimanche 23 avril 2017

How is std::is_integral implemented?

I am not familiar with Template magic in cpp. After reading what 'TemplateRex' said in this link, I was confused about how std::is_intergral works.

template< class T >
struct is_integral
{
    static const bool value /* = true if T is integral, false otherwise */;
    typedef std::integral_constant<bool, value> type;
};

I can understand how SFINAE works and how traits works. After refering cppreference, implementation of 'is_pointer" was found instead of 'is_integral' which looks like this :

template< class T > struct is_pointer_helper     : std::false_type {};
template< class T > struct is_pointer_helper<T*> : std::true_type {};
template< class T > struct is_pointer : is_pointer_helper<typename std::remove_cv<T>::type> {};

Do 'is_integral' have similar implementation? How?

Aucun commentaire:

Enregistrer un commentaire