首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

BitmaskType

定义可用于表示一组常量值或这些值的任何组合的类型。此特性通常由整数类型实现,std::bitset,或者枚举%28作用域和非作用域%29,并附加操作符重载。

所需

位掩码类型支持有限数量的位掩码元素,这些元素是位掩码类型的不同的非零值,因此,对于任意一对ci和cj,Ci & Ci != 0Ci & Cj == 0此外,0用于表示没有设置值的空位掩码。

位运算符operator&,,,operator|,,,operator^,,,operator~,,,operator&=,,,operator|=,和operator^=为位掩码类型的值定义,并且具有与无符号整数上对应的内置运算符相同的语义,如果位掩码元素是两个不同的整数幂。

下列表达式格式良好,对于任何BitmaskType X都具有以下含义。

X |= Y

sets the value Y in the object X

X &= ~Y

clears the value Y in the object X

(X&Y) != 0

indicates that the value Y is set in the object X

每个可表示的位掩码元素定义为inline%28自C++17%29constexpr位掩码类型的值。

使用

以下标准库类型满足BitmaskType*

  • std::ctype_base::mask
  • std::ios_base::fmtflags
  • std::ios_base::iostate
  • std::ios_base::openmode
  • std::regex_traits::char_class_type
  • std::regex_constants::syntax_option_type
  • std::regex_constants::match_flag_type
  • std::launch

依赖于某些特定实现选项%28的代码。int n =std::ios_base::hex%29是不可移植的,因为std::ios_base::fmtflags不一定可以隐式转换为int...

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券