A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove
bitset

A fixed capacity bitset. This is the default implementation before 20.33.0.
From 20.33.0 the legacy version of etl::bitset can be selected by defining ETL_USE_LEGACY_BITSET.
STL equivalent: std::bitset

etl::bitset<size_t N>

The class inherits from etl::ibitset.
A reference to etl::ibitset may be used to access and manipulate any etl::bitset template instance.
Has a number of extensions over std::bitset. Can be considered similar to an array of bool.
____________________________________________________________________________________________________
Types

span_type       A mutable span type
const_span_type A non-mutable span type
element_t       The type used as the internal storage for a bitset.
                By default, this is a uint_least8_t.
                To  change this, define ETL_BITSET_ELEMENT_TYPE as an alternative type.
                i.e.
                #define ETL_BITSET_ELEMENT_TYPE uint32_t
____________________________________________________________________________________________________
Constructor

The initial state of the bitset is all clear (false).

etl::bitset<size_t SIZE>();
etl::bitset<size_t SIZE>(unsigned long value);
etl::bitset<size_t SIZE>(const char* str);
etl::bitset<size_t SIZE>(const wchar_t* str);
etl::bitset<size_t SIZE>(const char16_t* str);
etl::bitset<size_t SIZE>(const char32_t* str);
The bitset is either default constructed, initialised with a numeric value, or a text string of zeros and ones.
____________________________________________________________________________________________________
Modifiers

etl::bitset& set();
Set all bits.
____________________________________________________________________________________________________
etl::bitset& set(const char* str);
etl::bitset& set(const wchar_t* str);
etl::bitset& set(const char16_t* str);
etl::bitset& set(const char32_t* str);
Set with a text string of  '0' and '1' characters.
____________________________________________________________________________________________________
etl::ibitset& set(size_t position, bool value = true);
Set a position to a one or zero, default one.
____________________________________________________________________________________________________
etl::ibitset& reset();
Reset all bits.
____________________________________________________________________________________________________
etl::ibitset& reset(size_t position);
Set a position to a zero.
____________________________________________________________________________________________________
etl::ibitset& from_string(const char*);
etl::ibitset& from_string(const wchar_t*);
etl::ibitset& from_string(const char16_t*);
etl::ibitset& from_string(const char32_t*);
Alias of set.
The bitset is built from a string of  '0' and '1' characters.
____________________________________________________________________________________________________
Access

template <typename T>
T value() const
Returns the value corresponding to the bitset.
T specifies the integral type to convert to.

unsigned long to_ulong() const
unsigned long long to_ullong() const
Functions for compatibility with the STL.
Calls value<unsigned long>() or value<unsigned long long>().

If called on an etl::bitset and the type is too small to contain the bitset size, a compile error will result.
If called on an etl::ibitset reference and the type is too small to contain the bitset size, a zero will be returned and
an optional exception/assert/error call will be emitted.
____________________________________________________________________________________________________
template <typename TString = etl::string<MAXN>>  If ETL_CPP11_SUPPORTED == 1
template <typename TString>                      If ETL_CPP11_SUPPORTED == 0
TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
                  typename TString::value_type one  = typename TString::value_type('1')) const
Returns the value as a string of '0' and '1' characters.
____________________________________________________________________________________________________
etl::ibitset::span_type span()
etl::ibitset::const_span_type span() const
Returns an etl::span of the underlying binary data.
The span is ordered LSB to MSB.
____________________________________________________________________________________________________
Bit access

bool operator[](size_t position) const

Returns the boolean state of the indexed bit.
position is not checked for validity.
____________________________________________________________________________________________________
size_t count() const
Returns the number of set bits.
____________________________________________________________________________________________________
size_t size() const
Returns the number of bits supported by this bitset.
____________________________________________________________________________________________________
bool test(size_t position) const
Returns the boolean state of the indexed bit.
position is not checked for validity.
____________________________________________________________________________________________________
bool any() const
Returns true if any of the bits are set, otherwise false.
____________________________________________________________________________________________________
bool none() const
Returns true if none of the bits are set, otherwise false.
____________________________________________________________________________________________________
bool all() const
Returns true if al of the bits are set, otherwise false.
____________________________________________________________________________________________________
size_t find_first(bool state) const

Returns the position of the first bit in the specified state. If not found then returns bitset<>::npos.
____________________________________________________________________________________________________
size_t find_next(bool state, size_t position) const
Returns the position of the next bit in the specified state, starting from position. If not found then returns
bitset<>::npos.
position is not checked for validity.
____________________________________________________________________________________________________
Bit operations

bitset<size_t N>& operator &= (const bitset<size_t N>& rhs);
bitset<size_t N>& operator |= (const bitset<size_t N>& rhs);
bitset<size_t N>& operator ^= (const bitset<size_t N>& rhs);
bitset<size_t N>& operator <<= (size_t shift);
bitset<size_t N>& operator >>= (size_t shift);
bool operator == (const bitset<size_t N>& rhs);
bool operator != (const bitset<size_t N>& rhs);
____________________________________________________________________________________________________
Non-member functions

void swap(etl::bitset<N>& lhs, etl::bitset<N>& rhs)

Swaps the contents of the two bitsets.
The bitsets must be the same size.
bitset.h