19 Haziran 2020 Cuma

std::is_enum

Giriş
Açıklaması şöyle
Checks whether T is an enumeration type. Provides the member constant value which is equal to true, if T is an enumeration type. Otherwise, value is equal to false.
Örnek
scoped enum ve unscoped enum arasındaki fark şöyle.
// Event types
enum class tPass     : uint8_t  {}; 
enum       tFailType            {}; 
Açıklaması şöyle.
A key distinction between unscoped enumerations and the scoped kind (enum class), is that the former implicitly convert to their underlying type, whereas the latter do not.
Bu iki enum tipini ayırmak için şöyle yaparız.
static_assert(std::is_enum<TEvent>::value, "Must be a scoped enum!"); 
static_assert(
 !std::is_convertible<TEvent, typename std::underlying_type<TEvent>::type>::value,
 "Must be a scoped enum!");
Örnek
enum'a göre SFINAE yapmak için şöyle yaparız
template<typename Ty, bool = std::is_integral<Ty>::value || std::is_enum<Ty>::value>
struct make_signed_if_possible_impl;

template<typename Ty>
struct make_signed_if_possible_impl<Ty, true>
{
    typedef typename std::make_signed<Ty>::type type;
};

template<typename Ty>
struct make_signed_if_possible_impl<Ty, false>
{
    typedef Ty type;
};

//
// Helper that only applies std::make_signed to types that can take it.
// For all other types 'type' is an alias for 'Ty'.
template<typename Ty>
struct make_signed_if_possible
{
    typedef typename make_signed_if_possible_impl<Ty>::type type;
};

Hiç yorum yok:

Yorum Gönder