C++ Bitset Library - all() Function



Description

The C++ function std::bitset::all() tests whether all bits from bitset are set or not.

Declaration

Following is the declaration for std::bitset::all() function form std::bitset header.

C++11

bool all() const noexcept;

Parameters

None

Return value

Returns true if all bits are set otherwise false.

Exceptions

This member function never throws exception.

Example

The following example shows the usage of std::bitset::all() function.

#include <iostream>
#include <bitset>

using namespace std;

int main(void) {
   bitset<4> b;
   bitset<4> mask("1111");

   if (!b.all())
      cout << "All bits are not set." << endl;

   b |= mask;

   if (b.all())
      cout << "All bit are set." << endl;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

All bits are not set.
All bit are set.
bitset.htm
Advertisements