名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | 工具庫‎ | bitset
 
 
 
 
bool all() const;
(1) (C++11 起無異常丟擲)
(C++23 起為 constexpr)
bool any() const;
(2) (C++11 起無異常丟擲)
(C++23 起為 constexpr)
bool none() const;
(3) (C++11 起無異常丟擲)
(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 的位數
(public 成員函式) [編輯]
(C++20)
計算無符號整數中 1 位的數量
(函式模板) [編輯]