bit::vector — Size Queries

How many elements are in the bit-vector?

1constexpr std::size_t size() const;
2constexpr bool empty() const;
1
Returns the number of elements in the bit-vector.
2
Returns true if the bit-vector has no elements (so size() == 0), returns false otherwise.

Example

#include <bit/bit.h>
int main()
{
    bit::vector<> v1;
    auto v2 = bit::vector<>::checker_board(4);
    std::cout
        << "vector\t\t" << "size\t" << "empty?\n"
        << v1 << "\t\t" << v1.size() << '\t' << v1.empty() << '\n'
        << v2 << '\t'   << v2.size() << '\t' << v2.empty() << '\n';
}

Output

vector          size    empty?
[]              0       1
[0 1 0 1]       4       0

See Also

vector::count
vector::description

Back to top