就你期望的用法而言,可以参考标准库future中std::launch的做法,通过重载运算符的方式实现自定义enum class的运算。比如:enum class Foo {...};Foo operator&(Foo lhs, Foo rhs) { using T = typename std::underlying_type<Foo>::type; return static_cast<Foo>( static_cast<T>(lhs) & static_cast<T...
1) C++98 的 enum是“非域内的”;而 C++11 的 enum class是“域内的”,限制了枚举成员只在域内可见 2) enum class 的缺省潜在类型 (underlying type) 是 int 型,而 enum 没有缺省潜在类型 3) enum class一般总是前置声明,而 enum 只有在指定了潜在类型时才可以是前置声明 参考资料 《Effective Modern ...
这里首先给出某些概念的定义。 6.10.4 基本类型(underlying type) 表达式的类型是指其运算结果的类型。当两个 long 类型的值相加时,表达式具有 long 类型。大多数数值运算符产生其类型依赖于操作数类型的结果。另一方面,某些操作符会给出具有 int 类型的布尔结果而不管其操作数类型如何。所以,举例来说,当两个 lon...
规则19.1(建议): 文件中的#include 语句之前只能是其他预处理指令或注释。 代码文件中所有#include 指令应该成组放置在接近文件顶部的位置。本规则说明,文件中可以优先#include 语句放置的只能是其他预处理指令或注释。 规则19.2(建议): #include 指令中的头文件名字里不能出现非标准字符。[未定义 14] ...
class settings { ... }; // as above int main() { // since C++11, use std::underlying_type to determine the underlying type of an enum typedef std::underlying_type< settings::flags> ::type flags_t; auto val = settings::bit1; switch (static_cast< flags_t> (val)) { case setti...
worse, they might compare equal because they happen to share the same underlying integer value ("ah yes, this nail IS a Panasonic electronic toothbrush"). Now, with strongly typed enums, the compiler will tell you that you're doing it. If you really mean it, you can always use atypecas...
Compiler warning (level 4) C4471'enumeration': a forward declaration of an unscoped enumeration must have an underlying type (int assumed) Compiler warning (level 1) C4472'identifier' is a native enum: add an access specifier (private/public) to declare a 'WinRT|managed' enum ...
The compiler now ranks enum conversions according to N4800 11.3.3.2 Ranking implicit conversion sequences (4.2):A conversion that promotes an enumeration whose underlying type is fixed to its underlying type is better than one that promotes to the promoted underlying type, if the two are ...
HasLeadingZeroes =0;// Set the long length modifier for wide charactersif(QT->getPointeeType()->isWideCharType()) LM.setKind(LengthModifier::AsWideChar);elseLM.setKind(LengthModifier::None);returntrue; }// If it's an enum, get its underlying type.if(constEnumType *ETy = QT->getAs...
P0340R3 SFINAE-Friendly underlying_type VS 2019 16,5 14 P0356R5 bind_front() VS 2019 16,5 20 P0439R0 enum class memory_order VS 2019 16,5 20 P0553R4 <bit> Rotating And Counting Functions VS 2019 16,5 20 P0556R3 <bit> ispow2(), ceil2(), floor2(), log2...