tetl 0.1.0
Embedded Template Library
|
The class template bitset represents a fixed-size sequence of Bits bits. Bitsets can be manipulated by standard logic operators. More...
#include <etl/bitset.hpp>
Public Types | |
using | reference = basic_bitset<Bits, etl::size_t>::reference |
Public Member Functions | |
constexpr | bitset () noexcept=default |
Constructs a bitset with all bits set to zero. | |
template<typename CharT, typename Traits> | |
constexpr | bitset (basic_string_view< CharT, Traits > const &str, typename basic_string_view< CharT, Traits >::size_type pos=0, typename basic_string_view< CharT, Traits >::size_type n=basic_string_view< CharT, Traits >::npos, CharT zero=CharT('0'), CharT one=CharT('1')) |
Constructs a bitset using the characters in the etl::basic_string_view str. | |
template<typename CharT> | |
constexpr | bitset (CharT const *str, typename basic_string_view< CharT >::size_type n=basic_string_view< CharT >::npos, CharT zero=CharT('0'), CharT one=CharT('1')) |
Constructs a bitset using the characters in the char const* str. | |
constexpr | bitset (unsigned long long val) noexcept |
Constructs a bitset, initializing the first (rightmost, least significant) M bit positions to the corresponding bit values of val, where M is the smaller of the number of bits in an unsigned long long and the number of bits Bits in the bitset being constructed. If M is less than Bits (the bitset is longer than 64 bits, for typical implementations of unsigned long long), the remaining bit positions are initialized to zeroes. | |
constexpr auto | all () const noexcept -> bool |
Checks if all bits are set to true. | |
constexpr auto | any () const noexcept -> bool |
Checks if any bits are set to true. | |
constexpr auto | count () const noexcept -> size_t |
Returns the number of bits that are set to true. | |
constexpr auto | flip () noexcept -> bitset & |
Flips all bits (like operator~, but in-place). | |
constexpr auto | flip (size_t pos) noexcept -> bitset & |
Flips the bit at the position pos. | |
constexpr auto | none () const noexcept -> bool |
Checks if none bits are set to true. | |
constexpr auto | operator&= (bitset const &other) noexcept -> bitset & |
Sets the bits to the result of binary AND on corresponding pairs of bits of *this and other. | |
constexpr auto | operator== (bitset const &rhs) const noexcept -> bool |
Returns true if all of the bits in *this and rhs are equal. | |
constexpr auto | operator[] (size_t const pos) -> reference |
Returns a reference like proxy to the bit at the position pos. Perfoms no bounds checking. | |
constexpr auto | operator[] (size_t const pos) const -> bool |
Returns the value of the bit at the position pos. Perfoms no bounds checking. | |
constexpr auto | operator^= (bitset const &other) noexcept -> bitset & |
Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and other. | |
constexpr auto | operator|= (bitset const &other) noexcept -> bitset & |
Sets the bits to the result of binary OR on corresponding pairs of bits of *this and other. | |
constexpr auto | operator~ () const noexcept -> bitset |
Returns a temporary copy of *this with all bits flipped (binary NOT). | |
constexpr auto | reset () noexcept -> bitset & |
Sets all bits to false. | |
constexpr auto | reset (size_t pos) noexcept -> bitset & |
Sets the bit at position pos to false. | |
constexpr auto | set () noexcept -> bitset & |
Sets all bits to true. | |
constexpr auto | set (etl::size_t pos, bool value=true) -> bitset & |
Sets the bit at the given position to the given value. | |
constexpr auto | size () const noexcept -> size_t |
Returns the number of bits that the bitset holds. | |
constexpr auto | test (size_t const pos) const -> bool |
Returns the value of the bit at the position pos. Perfoms no bounds checking. | |
template<size_t Capacity, typename CharT = char, typename Traits = char_traits<CharT>> requires (Capacity >= Bits) | |
constexpr auto | to_string (CharT zero=CharT('0'), CharT one=CharT('1')) const -> basic_inplace_string< CharT, Capacity, Traits > |
Converts the contents of the bitset to a string. Uses zero to represent bits with value of false and one to represent bits with value of true. The resulting string contains Bits characters with the first character corresponds to the last (Bits-1th) bit and the last character corresponding to the first bit. | |
constexpr auto | to_ullong () const noexcept -> unsigned long long requires(etl::numeric_limits< unsigned long long >::digits >=Bits) |
Converts the contents of the bitset to an unsigned long long integer. The first bit corresponds to the least significant digit of the number and the last bit corresponds to the most significant digit. | |
constexpr auto | to_ulong () const noexcept -> unsigned long requires(etl::numeric_limits< unsigned long >::digits >=Bits) |
Converts the contents of the bitset to an unsigned long integer. The first bit corresponds to the least significant digit of the number and the last bit corresponds to the most significant digit. | |
Friends | |
constexpr auto | operator& (bitset const &lhs, bitset const &rhs) noexcept -> bitset |
Performs binary AND between two bitsets, lhs and rhs. | |
constexpr auto | operator^ (bitset const &lhs, bitset const &rhs) noexcept -> bitset |
Performs binary XOR between two bitsets, lhs and rhs. | |
constexpr auto | operator| (bitset const &lhs, bitset const &rhs) noexcept -> bitset |
Performs binary OR between two bitsets, lhs and rhs. | |
The class template bitset represents a fixed-size sequence of Bits bits. Bitsets can be manipulated by standard logic operators.
using reference = basic_bitset<Bits, etl::size_t>::reference |
|
constexprdefaultnoexcept |
Constructs a bitset with all bits set to zero.
|
inlineconstexprnoexcept |
Constructs a bitset, initializing the first (rightmost, least significant) M bit positions to the corresponding bit values of val, where M is the smaller of the number of bits in an unsigned long long and the number of bits Bits in the bitset being constructed. If M is less than Bits (the bitset is longer than 64 bits, for typical implementations of unsigned long long), the remaining bit positions are initialized to zeroes.
|
inlineexplicitconstexpr |
Constructs a bitset using the characters in the etl::basic_string_view str.
An optional starting position pos and length n can be provided, as well as characters denoting alternate values for set (one) and unset (zero) bits. Traits::eq() is used to compare the character values. The effective length of the initializing string is min(n, str.size() - pos).
str | string used to initialize the bitset |
pos | a starting offset into str |
n | number of characters to use from str |
zero | alternate character for set bits in str |
one | alternate character for unset bits in str |
|
inlineexplicitconstexpr |
Constructs a bitset using the characters in the char const* str.
str | string used to initialize the bitset |
n | number of characters to use from str |
zero | alternate character for set bits in str |
one | alternate character for unset bits in str |
|
inlinenodiscardconstexprnoexcept |
Checks if all bits are set to true.
|
inlinenodiscardconstexprnoexcept |
Checks if any bits are set to true.
|
inlinenodiscardconstexprnoexcept |
Returns the number of bits that are set to true.
|
inlineconstexprnoexcept |
Flips all bits (like operator~, but in-place).
|
inlineconstexprnoexcept |
Flips the bit at the position pos.
pos | Index of the bit to be reset. |
|
inlinenodiscardconstexprnoexcept |
Checks if none bits are set to true.
|
inlineconstexprnoexcept |
Sets the bits to the result of binary AND on corresponding pairs of bits of *this and other.
|
inlinenodiscardconstexprnoexcept |
Returns true if all of the bits in *this and rhs are equal.
|
inlinenodiscardconstexpr |
Returns a reference like proxy to the bit at the position pos. Perfoms no bounds checking.
pos | Index of the bit. |
|
inlinenodiscardconstexpr |
Returns the value of the bit at the position pos. Perfoms no bounds checking.
pos | Index of the bit. |
|
inlineconstexprnoexcept |
Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and other.
|
inlineconstexprnoexcept |
Sets the bits to the result of binary OR on corresponding pairs of bits of *this and other.
|
inlineconstexprnoexcept |
Returns a temporary copy of *this with all bits flipped (binary NOT).
|
inlineconstexprnoexcept |
Sets all bits to false.
|
inlineconstexprnoexcept |
Sets the bit at position pos to false.
pos | Index of the bit to be reset. |
|
inlineconstexprnoexcept |
Sets all bits to true.
|
inlineconstexpr |
Sets the bit at the given position to the given value.
pos | Index of the bit to be modified. |
value | The new value for the bit. |
|
inlinenodiscardconstexprnoexcept |
Returns the number of bits that the bitset holds.
|
inlinenodiscardconstexpr |
Returns the value of the bit at the position pos. Perfoms no bounds checking.
pos | Index of the bit. |
|
inlinenodiscardconstexpr |
Converts the contents of the bitset to a string. Uses zero to represent bits with value of false and one to represent bits with value of true. The resulting string contains Bits characters with the first character corresponds to the last (Bits-1th) bit and the last character corresponding to the first bit.
|
inlinenodiscardconstexprnoexcept |
Converts the contents of the bitset to an unsigned long long integer. The first bit corresponds to the least significant digit of the number and the last bit corresponds to the most significant digit.
|
inlinenodiscardconstexprnoexcept |
Converts the contents of the bitset to an unsigned long integer. The first bit corresponds to the least significant digit of the number and the last bit corresponds to the most significant digit.
|
friend |
Performs binary AND between two bitsets, lhs and rhs.
|
friend |
Performs binary XOR between two bitsets, lhs and rhs.
|
friend |
Performs binary OR between two bitsets, lhs and rhs.