C++ Standard Library C++ STL Library

C++ <bitset> - all() Function



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

Syntax

bool all() const noexcept;

Parameters

No parameter is required.

Return Value

true if all bits are set to 1, false otherwise.

Exception

Never throws exceptions.

Example:

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

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

  if(!bset.all()) 
    cout<<"All bits in bset are not set.\n";

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

  if(bset.all()) 
    cout<<"All bits in bset are set.\n";

  return 0;
}

The output of the above code will be:

All bits in bset are not set.
All bits in bset are set.

❮ C++ <bitset> Library