本文介绍了是否可以确定类型是否为作用域枚举类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否存在类型特征,或者可以编写如下类型特征is_scoped_enum<T>:
Is there a type trait, or is it possible to write a type trait is_scoped_enum<T> such that:
- 如果T是作用域枚举,则is_scoped_enum<T>::value是true和
- 如果T是其他任何类型,则is_scoped_enum<T>::value为false
- if T is a scoped enumeration, is_scoped_enum<T>::value is true and
- if T is any other type, is_scoped_enum<T>::value is false
我认为测试它是否为枚举 和不能隐式转换为基础类型的应该可以解决问题.
I think testing if it is an enum and not implicitly convertible to the underlying type should do the trick.
template <typename T, bool B = std::is_enum<T>::value> struct is_scoped_enum : std::false_type {}; template <typename T> struct is_scoped_enum<T, true> : std::integral_constant<bool, !std::is_convertible<T, typename std::underlying_type<T>::type>::value> {};更多推荐
是否可以确定类型是否为作用域枚举类型?
发布评论