template<std::size_t size>
Magnum::Math::BoolVector class

Vector storing boolean values.

Template parameters
size Bit count

Result of component-wise comparison from Vector. The boolean values are stored as bits in array of unsigned bytes, unused bits have undefined value which doesn't affect comparison or all() / none() / any() functions. See also Operations with matrices and vectors for brief introduction.

Bit indexing

Value at position 0 is the lowest bit of the first byte passed in constructor. Value at position 8 is the lowest bit of the second byte passed in constructor. For example:

BoolVector4 a{0b0010};
Debug{} << a[1];  // true

Math::BoolVector<19> b{0b00001000, 0b00000011, 0b100};
Debug{} << b[3];  // true
Debug{} << b[8];  // true
Debug{} << b[9];  // true
Debug{} << b[18]; // true

Boolean operations

The class implements &&, || and ! operators component-wise, in other words equivalently to &, | and ~. This is done in order to have consistent behavior with boolean operations on scalar types — in the following example, it causes the final conversion to bool done at the end (instead of it happening already in the boolean subexpressions). Combined with operator bool() returning true only if all bits are set, this means the condition will be passed only if b is around a in all dimensions, and work the same way as if the variables were just scalars:

Vector3 a, b;

if(!(b < a - epsilon || a + epsilon < b)) {
    // b is around a
}

Public types

enum (anonymous): std::size_t { Size = size, DataSize = (size-1)/8+1 }

Constructors, destructors, conversion operators

BoolVector() constexpr noexcept
Default constructor.
BoolVector(ZeroInitT) explicit constexpr noexcept
Construct a zero-filled boolean vector.
BoolVector(NoInitT) explicit noexcept
Construct without initializing the contents.
template<class ... T>
BoolVector(UnsignedByte first, T... next) constexpr noexcept
Construct a boolean vector from segment values.
BoolVector(T value) explicit noexcept
Construct a boolean vector with one value for all fields.
template<class U, class V = decltype(Implementation::BoolVectorConverter<size, U>::from(std::declval<U>()))>
BoolVector(const U& other) explicit constexpr noexcept
Construct a boolean vector from external representation.
BoolVector(const BoolVector<size>&) defaulted constexpr noexcept
Copy constructor.
template<class U, class V = decltype(Implementation::BoolVectorConverter<size, U>::to(std::declval<BoolVector<size>>()))>
operator U() const explicit constexpr
Convert a boolean vector to external representation.
operator bool() const explicit
Boolean conversion.

Public functions

auto data() -> UnsignedByte*
Raw data.
auto data() const -> const UnsignedByte* constexpr
auto operator[](std::size_t i) const -> bool constexpr
Bit at given position.
auto set(std::size_t i, bool value) -> BoolVector<size>&
Set a bit at given position.
auto operator==(const BoolVector<size>& other) const -> bool
Equality comparison.
auto operator!=(const BoolVector<size>& other) const -> bool
Non-equality comparison.
auto all() const -> bool
Whether all bits are set.
auto none() const -> bool
Whether no bits are set.
auto any() const -> bool
Whether any bit is set.
auto operator~() const -> BoolVector<size>
Bitwise inversion.
auto operator!() const -> BoolVector<size> new in 2019.10
Component-wise boolean negation.
auto operator&=(const BoolVector<size>& other) -> BoolVector<size>&
Bitwise AND and assign.
auto operator&(const BoolVector<size>& other) const -> BoolVector<size>
Bitwise AND.
auto operator&&(const BoolVector<size>& other) const -> BoolVector<size> new in 2019.10
Component-wise boolean AND.
auto operator|=(const BoolVector<size>& other) -> BoolVector<size>&
Bitwise OR and assign.
auto operator|(const BoolVector<size>& other) const -> BoolVector<size>
Bitwise OR.
auto operator||(const BoolVector<size>& other) const -> BoolVector<size> new in 2019.10
Component-wise boolean OR.
auto operator^=(const BoolVector<size>& other) -> BoolVector<size>&
Bitwise XOR and assign.
auto operator^(const BoolVector<size>& other) const -> BoolVector<size>
Bitwise XOR.

Enum documentation

template<std::size_t size>
enum Magnum::Math::BoolVector<size>::(anonymous): std::size_t

Enumerators
Size

Vector size

DataSize

Vector storage size

Function documentation

template<std::size_t size>
Magnum::Math::BoolVector<size>::BoolVector() constexpr noexcept

Default constructor.

Equivalent to BoolVector(ZeroInitT).

template<std::size_t size> template<class ... T>
Magnum::Math::BoolVector<size>::BoolVector(UnsignedByte first, T... next) constexpr noexcept

Construct a boolean vector from segment values.

Parameters
first Value for first 8bit segment
next Values for next Bbit segments

template<std::size_t size>
Magnum::Math::BoolVector<size>::operator bool() const explicit

Boolean conversion.

Equivalent to all().

template<std::size_t size>
UnsignedByte* Magnum::Math::BoolVector<size>::data()

Raw data.

Returns Array of DataSize length

template<std::size_t size>
const UnsignedByte* Magnum::Math::BoolVector<size>::data() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<std::size_t size>
bool Magnum::Math::BoolVector<size>::all() const

Whether all bits are set.

template<std::size_t size>
bool Magnum::Math::BoolVector<size>::none() const

Whether no bits are set.

template<std::size_t size>
bool Magnum::Math::BoolVector<size>::any() const

Whether any bit is set.

template<std::size_t size>
BoolVector<size> Magnum::Math::BoolVector<size>::operator!() const new in 2019.10

Component-wise boolean negation.

Equivalent to operator~(). See Boolean operations for more information.

template<std::size_t size>
BoolVector<size>& Magnum::Math::BoolVector<size>::operator&=(const BoolVector<size>& other)

Bitwise AND and assign.

The computation is done in-place.

template<std::size_t size>
BoolVector<size> Magnum::Math::BoolVector<size>::operator&(const BoolVector<size>& other) const

Bitwise AND.

template<std::size_t size>
BoolVector<size> Magnum::Math::BoolVector<size>::operator&&(const BoolVector<size>& other) const new in 2019.10

Component-wise boolean AND.

Equivalent to operator&(). See Boolean operations for more information.

template<std::size_t size>
BoolVector<size>& Magnum::Math::BoolVector<size>::operator|=(const BoolVector<size>& other)

Bitwise OR and assign.

The computation is done in-place.

template<std::size_t size>
BoolVector<size> Magnum::Math::BoolVector<size>::operator|(const BoolVector<size>& other) const

Bitwise OR.

template<std::size_t size>
BoolVector<size> Magnum::Math::BoolVector<size>::operator||(const BoolVector<size>& other) const new in 2019.10

Component-wise boolean OR.

Equivalent to operator|(). See Boolean operations for more information.

template<std::size_t size>
BoolVector<size>& Magnum::Math::BoolVector<size>::operator^=(const BoolVector<size>& other)

Bitwise XOR and assign.

The computation is done in-place.

template<std::size_t size>
BoolVector<size> Magnum::Math::BoolVector<size>::operator^(const BoolVector<size>& other) const

Bitwise XOR.

template<std::size_t size> template<std::size_t size>
Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, const BoolVector<size>& value)

Debug output operator.

In order to avoid potential confusion, prints the value as a comma-separated sequence of binary literals, so the output corresponds to how the value would be constructed. For example,

Debug{} << BoolVector4{0b1010}
        << Math::BoolVector<19>{0b00001000, 0b00000011, 0b100};

prints as

BoolVector(0b1010) BoolVector(0b00001000, 0b00000011, 0b100)

Note that this, on the other hand, makes mapping to bit indices less obvious — see Bit indexing for more information.