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

来自cppreference.com
< cpp‎ | utility‎ | bitset
 
 
工具库
通用工具
格式化库 (C++20)
(C++11)
关系运算符 (C++20 中弃用)
整数比较函数
(C++20)(C++20)(C++20)
(C++20)
swap 与类型运算
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
常用词汇类型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)

初等字符串转换
(C++17)
(C++17)
栈踪
 
 
bool all() const noexcept;
(1) (C++11 起)
(2)
bool any() const;
(C++11 前)
bool any() const noexcept;
(C++11 起)
(3)
bool none() const;
(C++11 前)
bool none() const noexcept;
(C++11 起)

检查是否全部、任一或无位被设为 true

1) 检查是否全部位被设为 true
2) 检查是否任一位被设为 true
3) 检查是否无位被设为 true

目录

[编辑] 参数

(无)

[编辑] 返回值

1) 若全部位被设为 true 则为 true ,否则为 false
2) 若任何一位被设为 true 则为 true ,否则为 false
3) 若无位被设为 true 则为 true ,否则为 false

[编辑] 示例

#include <iostream>
#include <bitset>
 
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";
    std::cout << b1 << '\t' << b1.all() << '\t' << b1.any() << '\t' << b1.none() << '\n';
    std::cout << b2 << '\t' << b2.all() << '\t' << b2.any() << '\t' << b2.none() << '\n';
    std::cout << 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

[编辑] 参阅

返回设置为 true 的位的数量
(公开成员函数) [编辑]
(C++20)
计量无符号整数中为 1 的位的数量
(函数模板) [编辑]