template<std::size_t size>
Magnum::Math::BitVector class new in Git master

Vector of bits.

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:

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

Math::BitVector<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 to be 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 + 7)/8 }

Constructors, destructors, conversion operators

BitVector() constexpr noexcept
Default constructor.
BitVector(ZeroInitT) explicit constexpr noexcept
Construct a zero-filled bit vector.
BitVector(Magnum::NoInitT) explicit noexcept
Construct without initializing the contents.
template<class ... T>
BitVector(UnsignedByte first, T... next) constexpr noexcept
Construct a bit vector from segment values.
BitVector(T value) explicit noexcept
Construct a bit vector with one value for all fields.
template<class U, class = decltype(Implementation::BitVectorConverter<size, U>::from(std::declval<U>()))>
BitVector(const U& other) explicit constexpr noexcept
Construct a bit vector from external representation.
template<class U, class = decltype(Implementation::BitVectorConverter<size, U>::to(std::declval<BitVector<size>>()))>
operator U() const explicit constexpr
Convert the bit 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) -> BitVector<size>& new in Git master
Set a bit at given position.
auto reset(std::size_t i) -> BitVector<size>& new in Git master
Reset a bit at given position.
auto set(std::size_t i, bool value) -> BitVector<size>&
Set or reset a bit at given position.
auto operator==(const BitVector<size>& other) const -> bool
Equality comparison.
auto operator!=(const BitVector<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 -> BitVector<size>
Bitwise inversion.
auto operator!() const -> BitVector<size> new in 2019.10
Component-wise boolean negation.
auto operator&=(const BitVector<size>& other) -> BitVector<size>&
Bitwise AND and assign.
auto operator&(const BitVector<size>& other) const -> BitVector<size>
Bitwise AND.
auto operator&&(const BitVector<size>& other) const -> BitVector<size> new in 2019.10
Component-wise boolean AND.
auto operator|=(const BitVector<size>& other) -> BitVector<size>&
Bitwise OR and assign.
auto operator|(const BitVector<size>& other) const -> BitVector<size>
Bitwise OR.
auto operator||(const BitVector<size>& other) const -> BitVector<size> new in 2019.10
Component-wise boolean OR.
auto operator^=(const BitVector<size>& other) -> BitVector<size>&
Bitwise XOR and assign.
auto operator^(const BitVector<size>& other) const -> BitVector<size>
Bitwise XOR.

Enum documentation

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

Enumerators
Size

Vector size

DataSize

Vector storage size

Function documentation

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

Default constructor.

Equivalent to BitVector(ZeroInitT).

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

Construct a bit vector from segment values.

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

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

Boolean conversion.

Equivalent to all().

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

Raw data.

Contrary to what Doxygen shows, returns reference to an one-dimensional fixed-size array of DataSize elements, i.e. UnsignedByte(&)[DataSize].

template<std::size_t size>
const UnsignedByte* Magnum::Math::BitVector<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>
BitVector<size>& Magnum::Math::BitVector<size>::set(std::size_t i, bool value)

Set or reset a bit at given position.

Prefer to use set(std::size_t) and reset(std::size_t) where possible as that's a simpler operation.

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

Whether all bits are set.

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

Whether no bits are set.

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

Whether any bit is set.

template<std::size_t size>
BitVector<size> Magnum::Math::BitVector<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>
BitVector<size>& Magnum::Math::BitVector<size>::operator&=(const BitVector<size>& other)

Bitwise AND and assign.

The computation is done in-place.

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

Bitwise AND.

template<std::size_t size>
BitVector<size> Magnum::Math::BitVector<size>::operator&&(const BitVector<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>
BitVector<size>& Magnum::Math::BitVector<size>::operator|=(const BitVector<size>& other)

Bitwise OR and assign.

The computation is done in-place.

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

Bitwise OR.

template<std::size_t size>
BitVector<size> Magnum::Math::BitVector<size>::operator||(const BitVector<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>
BitVector<size>& Magnum::Math::BitVector<size>::operator^=(const BitVector<size>& other)

Bitwise XOR and assign.

The computation is done in-place.

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

Bitwise XOR.

template<std::size_t size> template<std::size_t size>
Debug& operator<<(Debug& debug, const BitVector<size>& value) new in Git master

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{} << BitVector4{0b1010}
        << Math::BitVector<19>{0b00001000, 0b00000011, 0b100};

prints as

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

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