Namespaces
Variants

std::bitset<N>::all, std::bitset<N>::any, std::bitset<N>::none

来自 zh.cppreference.net
 
 
工具库
语言支持
类型支持(基本类型、RTTI)
库功能特性测试宏 (C++20 起)
程序工具
可变参数函数
(C++11 起)
(C++20 起)
协程支持 (C++20 起)
契约支持 (C++26 起)
三路比较
(C++20 起)
(C++20 起)
(C++20 起)
(C++20 起)
(C++20 起)
(C++20 起)
(C++20 起)(C++20 起)(C++20 起)    
(C++20 起)(C++20 起)(C++20 起)

通用工具
函数对象
位操作 (C++20 起)
(C++11 起)
关系运算符 (C++20 中弃用)
整数比较函数
(C++20 起)(C++20 起)(C++20 起)    
(C++20 起)(C++20 起)(C++20 起)
(C++20 起)
交换和类型操作
(C++20 起)
(C++14 起)
(C++11 起)
(C++23 起)
(C++11 起)
(C++23 起)
(C++11 起)
(C++11 起)
(C++17 起)
常用词汇类型
(C++11 起)
(C++17 起)
(C++17 起)
(C++17 起)
(C++11 起)
(C++11 起)
(C++17 起)
(C++17 起)
(C++23 起)



 
 
bool all() const;
(1) (C++11 起为 noexcept)
(C++23 起为 constexpr)
bool any() const;
(2) (C++11 起为 noexcept)
(C++23 起为 constexpr)
bool none() const;
(3) (C++11 起为 noexcept)
(C++23 起为 constexpr)
1) 检查是否所有位都被设置为 true.
2) 检查是否有任何位被设置为 true.
3) 检查是否没有位被设置为 true.

返回值

1) true 如果所有位都设置为 true ,否则为 false 。
2) 若任意位被设置为 true ,则返回 true ;否则返回 false 。
3) true 如果所有位均未设置为 true ,否则为 false 。

示例

#include <bitset>
#include <iostream>
int main()
{
    std::bitset<4> b1("0000");
    std::bitset<4> b2("0101");
    std::bitset<4> b3("1111");
    std::cout
        << "bitset\t" << "all\t" << "any\t" << "none\n"
        << b1 << '\t' << b1.all() << '\t' << b1.any() << '\t' << b1.none() << '\n'
        << b2 << '\t' << b2.all() << '\t' << b2.any() << '\t' << b2.none() << '\n'
        << b3 << '\t' << b3.all() << '\t' << b3.any() << '\t' << b3.none() << '\n';
}

输出:

bitset  all any none
0000    0   0   1
0101    0   1   0
1111    1   1   0

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 应用于 发布时的行为 正确行为
LWG 693 C++98 未提供成员函数 all() 已提供

参见

返回被设置为 true 的比特数量
(公开成员函数)
(C++20)
计算无符号整数中 1 比特的数量
(函数模板)