C++ Standard Library C++ STL Library

C++ <bitset> - none() Function



The C++ bitset::none function is used to check if none of the bits of the bitset is set (i.e., check whether no bit is set to 1).

Syntax

bool none() const;
bool none() const noexcept;

Parameters

No parameter is required.

Return Value

true if no bit is set to 1, false otherwise.

Exception

Never throws exceptions.

Example:

In the example below, the bitset::none function is used to check whether none of the bits in the given bitset is set or not.

#include <iostream>
#include <bitset>
using namespace std;
 
int main (){
  bitset<5> bset;

  if(bset.none()) 
    cout<<"None of the bits in bset is set.\n";

  bset =  bitset<5>("11011");

  if(!bset.none()) 
    cout<<"At least one bit in bset is set.\n";

  return 0;
}

The output of the above code will be:

None of the bits in bset is set.
At least one bit in bset is set.

❮ C++ <bitset> Library