public member function
<bitset>

std::bitset::size

size_t size() const;
constexpr size_t size() noexcept;
Return size
Returns the number of bits in the bitset.

This is the template parameter with which the bitset class is instantiated (template parameter N).

Parameters

none

Return Value

The number of bits in the bitset.

size_t is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// bitset::size
#include <iostream>       // std::cout
#include <bitset>         // std::bitset

int main ()
{
  std::bitset<8> foo;
  std::bitset<4> bar;

  std::cout << "foo.size() is " << foo.size() << '\n';
  std::cout << "bar.size() is " << bar.size() << '\n';

  return 0;
}


Output:

foo.size() is 8
bar.size() is 4

Data races

None (compile-time constant).

Exception safety

No-throw guarantee: never throws exceptions.

See also