bit::matrix — Is a Bit-Matrix Special?

Check to see if this bit-matrix is “special” in some way.

1constexpr bool is_zero() const;
2constexpr bool is_ones() const;
3constexpr bool is_identity() const;
4constexpr bool is_square()   const;
5constexpr bool is_symmetric() const;
1
Are all the bit-matrix elements all 0?
2
Are all the bit-matrix elements all 1?
3
Is this bit-matrix square? Empty bit-matrices are NOT considered to be square.
4
Is this the identity bit-matrix?
5
Is this the bit-matrix symmetric (must be square)

Example

#include <bit/bit.h>
int main()
{
    auto ident = bit::matrix<>::identity(8);

    // Little lambda that turns a bool into a string
    auto b2s = [](bool x) { return x ? "YES" : "NO"; };

    std::cout << "bit-matrix is_zero?      " << b2s(ident.is_zero())      << "\n";
    std::cout << "bit-matrix is_ones?      " << b2s(ident.is_ones())      << "\n";
    std::cout << "bit-matrix is_identity?  " << b2s(ident.is_identity())  << "\n";
    std::cout << "bit-matrix is_square?    " << b2s(ident.is_square())    << '\n';
    std::cout << "bit-matrix is_symmetric? " << b2s(ident.is_symmetric()) << "\n";
}

Output

bit-matrix is_zero?      NO
bit-matrix is_ones?      NO
bit-matrix is_identity?  YES
bit-matrix is_square?    YES
bit-matrix is_symmetric? YES

See Also

matrix::ones
matrix::zeros
matrix::identity

Back to top