BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
bio::ranges::dynamic_bitset< bit_capacity > Class Template Reference

A constexpr bitset implementation with dynamic size at compile time. More...

#include <bio/ranges/container/dynamic_bitset.hpp>

+ Inheritance diagram for bio::ranges::dynamic_bitset< bit_capacity >:

Public Types

Associated types
using value_type = bool
 Equals bool.
 
using reference = detail::dynamic_bitset_reference_proxy
 A proxy type that enables assignment.
 
using const_reference = bool
 Equals the value_type.
 
using iterator = detail::random_access_iterator< dynamic_bitset >
 The iterator type of this container (a random access iterator).
 
using const_iterator = detail::random_access_iterator< dynamic_bitset const >
 The const_iterator type of this container (a random access iterator).
 
using difference_type = ptrdiff_t
 A std::ptrdiff_t.
 
using size_type = meta::detail::min_viable_uint_t< bit_capacity >
 An unsigned integer type (usually std::size_t).
 

Public Member Functions

Constructors, destructor and assignment
constexpr dynamic_bitset () noexcept=default
 Defaulted.
 
constexpr dynamic_bitset (dynamic_bitset const &) noexcept=default
 Defaulted.
 
constexpr dynamic_bitset (dynamic_bitset &&) noexcept=default
 Defaulted.
 
constexpr dynamic_bitsetoperator= (dynamic_bitset const &) noexcept=default
 Defaulted.
 
constexpr dynamic_bitsetoperator= (dynamic_bitset &&) noexcept=default
 Defaulted.
 
 ~dynamic_bitset () noexcept=default
 Defaulted.
 
constexpr dynamic_bitset (uint64_t const value)
 Construct from an uint64_t.
 
template<std::forward_iterator begin_it_type, typename end_it_type >
requires (std::sentinel_for<end_it_type, begin_it_type> && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
constexpr dynamic_bitset (begin_it_type begin_it, end_it_type end_it) noexcept
 Construct from two iterators.
 
template<meta::different_from< dynamic_bitset > other_range_t>
requires std::ranges::input_range<other_range_t>
constexpr dynamic_bitset (other_range_t &&range) noexcept
 Construct from a different range.
 
constexpr dynamic_bitset (size_type const n, value_type const value) noexcept
 Construct with n times value.
 
constexpr dynamic_bitsetoperator= (std::initializer_list< value_type > const ilist) noexcept
 Assign from std::initializer_list.
 
template<size_t N>
constexpr dynamic_bitset (char const (&lit)[N])
 Construction from literal.
 
template<size_t N>
constexpr dynamic_bitsetoperator= (char const (&lit)[N])
 Assign from literal.
 
template<size_t N>
constexpr void assign (char const (&lit)[N])
 Assign from literal.
 
constexpr void assign (std::initializer_list< value_type > const ilist) noexcept
 Assign from std::initializer_list.
 
constexpr void assign (size_type const count, value_type const value) noexcept
 Assign with count times value.
 
template<std::ranges::input_range other_range_t>
requires std::constructible_from<value_type, std::ranges::range_reference_t<other_range_t>>
constexpr void assign (other_range_t &&range) noexcept
 Assign from a different range.
 
template<std::forward_iterator begin_it_type, typename end_it_type >
requires (std::sentinel_for<end_it_type, begin_it_type> && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
constexpr void assign (begin_it_type begin_it, end_it_type end_it) noexcept
 Assign from pair of iterators.
 
Iterators
constexpr iterator begin () noexcept
 Returns the begin to the dynamic_bitset.
 
constexpr const_iterator begin () const noexcept
 Returns the begin to the dynamic_bitset.
 
constexpr const_iterator cbegin () const noexcept
 Returns the begin to the dynamic_bitset.
 
constexpr iterator end () noexcept
 Returns iterator past the end of the dynamic_bitset.
 
constexpr const_iterator end () const noexcept
 Returns iterator past the end of the dynamic_bitset.
 
constexpr const_iterator cend () const noexcept
 Returns iterator past the end of the dynamic_bitset.
 
Bit manipulation
constexpr dynamic_bitsetoperator&= (dynamic_bitset const &rhs) noexcept
 Sets the bits to the result of binary AND on corresponding pairs of bits of *this and rhs.
 
constexpr dynamic_bitsetoperator|= (dynamic_bitset const &rhs) noexcept
 Sets the bits to the result of binary OR on corresponding pairs of bits of *this and rhs.
 
constexpr dynamic_bitsetoperator^= (dynamic_bitset const &rhs) noexcept
 Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and rhs.
 
constexpr dynamic_bitset operator~ () const noexcept
 Returns a temporary copy of *this with all bits flipped (binary NOT).
 
constexpr dynamic_bitsetoperator<<= (size_t const count) noexcept
 Performs binary shift left on the current object.
 
constexpr dynamic_bitsetoperator>>= (size_t const count) noexcept
 Performs binary shift right on the current object.
 
constexpr dynamic_bitset operator>> (size_t const count) const noexcept
 Performs binary shift right.
 
constexpr dynamic_bitset operator<< (size_t const count) const noexcept
 Performs binary shift left.
 
constexpr dynamic_bitsetset () noexcept
 Sets all bits to 1.
 
constexpr dynamic_bitsetset (size_t const i, bool const value=true)
 Sets the i'th bit to value.
 
constexpr dynamic_bitsetreset () noexcept
 Sets all bits to 0.
 
constexpr dynamic_bitsetreset (size_t const i)
 Sets the i'th bit to false.
 
constexpr dynamic_bitsetflip () noexcept
 Flips all bits (binary NOT).
 
constexpr dynamic_bitsetflip (size_t const i)
 Flips the i'th bit (binary NOT).
 
Element Access
constexpr bool all () const noexcept
 Checks if all bit are set.
 
constexpr bool any () const noexcept
 Checks if any bit is set.
 
constexpr bool none () const noexcept
 Checks if no bit is set.
 
constexpr size_type count () const noexcept
 Returns the number of set bits.
 
constexpr reference at (size_t const i)
 Returns the i-th element.
 
constexpr const_reference at (size_t const i) const
 Returns the i-th element.
 
constexpr const_reference test (size_t const i) const
 Returns the i-th element.
 
constexpr reference operator[] (size_t const i) noexcept
 Returns the i-th element.
 
constexpr const_reference operator[] (size_t const i) const noexcept
 Returns the i-th element.
 
constexpr reference front () noexcept
 Returns the first element.
 
constexpr const_reference front () const noexcept
 Returns the first element.
 
constexpr reference back () noexcept
 Returns the last element.
 
constexpr const_reference back () const noexcept
 Returns the last element.
 
constexpr detail::dynamic_bitset_bitfield * raw_data () noexcept
 Direct access to the underlying bit field.
 
constexpr detail::dynamic_bitset_bitfield const * raw_data () const noexcept
 Direct access to the underlying bit field.
 
Capacity
constexpr bool empty () const noexcept
 Checks whether the container is empty.
 
constexpr size_type size () const noexcept
 Returns the number of elements in the container, i.e. std::distance(begin(), end()).
 
constexpr size_type max_size () const noexcept
 Returns the maximum number of elements the container is able to hold and resolves to bit_capacity.
 
constexpr size_type capacity () const noexcept
 Returns the number of elements that the container is able to hold and resolves to bit_capacity.
 
constexpr void reserve (size_t) const noexcept
 Since the capacity is fixed on compile time, this is a no-op.
 
constexpr void shrink_to_fit () const noexcept
 Since the capacity is fixed on compile time, this is a no-op.
 
Modifiers
constexpr void clear () noexcept
 Removes all elements from the container.
 
constexpr iterator insert (const_iterator pos, value_type const value) noexcept
 Inserts value before pos in the container.
 
constexpr iterator insert (const_iterator pos, size_type const count, value_type const value) noexcept
 Inserts count copies of value before position in the container.
 
template<std::forward_iterator begin_it_type, typename end_it_type >
requires (std::sentinel_for<end_it_type, begin_it_type> && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
constexpr iterator insert (const_iterator pos, begin_it_type begin_it, end_it_type end_it) noexcept
 Inserts elements from range [begin_it, end_it) before pos in the container.
 
constexpr iterator insert (const_iterator pos, std::initializer_list< value_type > const &ilist) noexcept
 Inserts elements from initializer list before pos in the container.
 
constexpr iterator erase (const_iterator begin_it, const_iterator end_it) noexcept
 Removes specified elements from the container.
 
constexpr iterator erase (const_iterator pos) noexcept
 Removes specified elements from the container.
 
constexpr void push_back (value_type const value) noexcept
 Appends the given element value to the end of the container.
 
constexpr void pop_back () noexcept
 Removes the last element of the container.
 
constexpr void resize (size_type const count, value_type const value=false) noexcept
 Resizes the container to contain count elements.
 
constexpr void swap (dynamic_bitset &rhs) noexcept
 Swap contents with another instance.
 
constexpr void swap (dynamic_bitset &&rhs) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Conversions
constexpr unsigned long to_ulong () const
 Converts the dynamic_bitset to an unsigned long integer.
 
constexpr unsigned long long to_ullong () const
 Converts the dynamic_bitset to an unsigned long long integer.
 

Friends

template<size_t >
class dynamic_bitset
 Befriend other template instantiations of dynamic_bitset.
 
constexpr void swap (dynamic_bitset &lhs, dynamic_bitset &rhs) noexcept
 Swap contents with another instance.
 
Binary operators
template<size_t cap>
requires (cap <= bit_capacity)
constexpr dynamic_bitset operator& (dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
 Returns dynamic_bitset containing the result of binary AND on corresponding pairs of bits of lhs and rhs.
 
template<size_t cap>
requires (cap <= bit_capacity)
constexpr dynamic_bitset operator^ (dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
 Returns dynamic_bitset containing the result of binary XOR on corresponding pairs of bits of lhs and rhs.
 
template<size_t cap>
requires (cap <= bit_capacity)
constexpr dynamic_bitset operator| (dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
 Returns dynamic_bitset containing the result of binary OR on corresponding pairs of bits of lhs and rhs.
 
Comparison operators
template<size_t cap>
constexpr bool operator== (dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
 Performs element-wise comparison.
 
template<size_t cap>
constexpr auto operator<=> (dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
 Performs element-wise comparison.
 

Detailed Description

template<size_t bit_capacity = 58>
class bio::ranges::dynamic_bitset< bit_capacity >

A constexpr bitset implementation with dynamic size at compile time.

Template Parameters
bit_capacityThe capacity of the dynamic bitset

This implementation of a bitset can be constructed, accessed and modified at compile time. It has a fixed capacity but a dynamic size and provides all functionality of a sequence container. Note that it also models a reservable sequence container but all associated member functions are no-op because the capacity is fixed.

Example

int main()
{
bio::ranges::dynamic_bitset t1{"10001100"}; // Construct from string.
bio::ranges::dynamic_bitset const t2{0b1011'1000}; // Construct from binary literal or integer.
fmt::print("{}\n", t1); // Debug printing inserts separators: 1000'1100
fmt::print("{}\n", t2); // Standard printing does not: 10111000
t1 &= t2; // Assign t1 the result of a binary AND of t1 and t2.
fmt::print("{}\n", t1); // 1000'1000
}
A constexpr bitset implementation with dynamic size at compile time.
Definition: dynamic_bitset.hpp:142
A constexpr bitset implementation with dynamic size at compile time.
Core alphabet concept and free function/type trait wrappers.

Thread safety

This container provides no thread-safety beyond the promise given also by the STL that all calls to const member functions are safe from multiple threads (as long as no thread calls a non-const member function at the same time).

Constructor & Destructor Documentation

◆ dynamic_bitset() [1/5]

template<size_t bit_capacity = 58>
constexpr bio::ranges::dynamic_bitset< bit_capacity >::dynamic_bitset ( uint64_t const  value)
inlineconstexpr

Construct from an uint64_t.

Parameters
[in]valueThe uint64_t to construct/assign from.
Exceptions
std::invalid_argumentif value has bits set outside of [0, 58).

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111}; // Use binary literal.
bio::ranges::dynamic_bitset t2{0b0000'1000'1111}; // Leading zeros are stripped.
bio::ranges::dynamic_bitset t3{832}; // Use a number.
fmt::print("{}\n", t1); // 1011'1000'1111
fmt::print("{}\n", t2); // 1000'1111
fmt::print("{}\n", t3); // 1101'0000'00
}

Complexity

Constant.

Exceptions

Throws std::invalid_argument value has a set bit past the 58 one, i.e. only bits in [0,58) may be set.

◆ dynamic_bitset() [2/5]

template<size_t bit_capacity = 58>
template<std::forward_iterator begin_it_type, typename end_it_type >
requires (std::sentinel_for<end_it_type, begin_it_type> && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
constexpr bio::ranges::dynamic_bitset< bit_capacity >::dynamic_bitset ( begin_it_type  begin_it,
end_it_type  end_it 
)
inlineconstexprnoexcept

Construct from two iterators.

Template Parameters
begin_it_typeMust model std::forward_iterator and value_type must be constructible from the reference type of begin_it_type.
end_it_typeMust model std::sentinel_for.
Parameters
[in]begin_itBegin of range to construct/assign from.
[in]end_itEnd of range to construct/assign from.

Complexity

Linear in the distance between begin_it and end_it.

Exceptions

No-throw guarantee.

◆ dynamic_bitset() [3/5]

template<size_t bit_capacity = 58>
template<meta::different_from< dynamic_bitset > other_range_t>
requires std::ranges::input_range<other_range_t>
constexpr bio::ranges::dynamic_bitset< bit_capacity >::dynamic_bitset ( other_range_t &&  range)
inlineexplicitconstexprnoexcept

Construct from a different range.

Template Parameters
other_range_tThe type of range to be inserted; must satisfy std::ranges::input_range and value_type must be constructible from std::ranges::range_reference_t<other_range_t>.
Parameters
[in]rangeThe sequence to construct/assign from.

Complexity

Linear in the size of range.

Exceptions

No-throw guarantee.

◆ dynamic_bitset() [4/5]

template<size_t bit_capacity = 58>
constexpr bio::ranges::dynamic_bitset< bit_capacity >::dynamic_bitset ( size_type const  n,
value_type const  value 
)
inlineconstexprnoexcept

Construct with n times value.

Parameters
[in]nNumber of elements.
[in]valueThe initial value to be assigned.

Complexity

Linear in n.

Exceptions

No-throw guarantee.

◆ dynamic_bitset() [5/5]

template<size_t bit_capacity = 58>
template<size_t N>
constexpr bio::ranges::dynamic_bitset< bit_capacity >::dynamic_bitset ( char const (&)  lit[N])
inlineconstexpr

Construction from literal.

Parameters
[in]litThe literal to construct the string for. May only contain '0' and '1'.
Exceptions
std::invalid_argumentif any character is not '0' or '1'.

The char literal is expected to be null-terminated (asserted in debug-mode). If it is not, the last character will be lost when copying to the instance of dynamic_bitset.

Example

int main()
{
bio::ranges::dynamic_bitset t1{"101110001111"}; // Use character literal.
bio::ranges::dynamic_bitset t2{"000010001111"}; // Leading zeros are kept.
fmt::print("{}\n", t1); // 1011'1000'1111
fmt::print("{}\n", t2); // 0000'1000'1111
}

Complexity

Linear in the size of lit.

Exceptions

Throws std::invalid_argument if any character is not '0' or '1'.

Member Function Documentation

◆ all()

template<size_t bit_capacity = 58>
constexpr bool bio::ranges::dynamic_bitset< bit_capacity >::all ( ) const
inlineconstexprnoexcept

Checks if all bit are set.

Returns
true if all bits are set or the bitset is empty, false otherwise.

◆ any()

template<size_t bit_capacity = 58>
constexpr bool bio::ranges::dynamic_bitset< bit_capacity >::any ( ) const
inlineconstexprnoexcept

Checks if any bit is set.

Returns
true if any bit is set, false otherwise.

◆ assign() [1/5]

template<size_t bit_capacity = 58>
template<std::forward_iterator begin_it_type, typename end_it_type >
requires (std::sentinel_for<end_it_type, begin_it_type> && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::assign ( begin_it_type  begin_it,
end_it_type  end_it 
)
inlineconstexprnoexcept

Assign from pair of iterators.

Template Parameters
begin_it_typeMust model std::forward_iterator and the value_type must be constructible from the reference type of begin_it_type.
end_it_typeMust model std::sentinel_for.
Parameters
[in]begin_itBegin of range to construct/assign from.
[in]end_itEnd of range to construct/assign from.

Complexity

Linear in the distance between begin_it and end_it.

Exceptions

No-throw guarantee.

◆ assign() [2/5]

template<size_t bit_capacity = 58>
template<size_t N>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::assign ( char const (&)  lit[N])
inlineconstexpr

Assign from literal.

Parameters
[in]litThe literal to assign the string from. May only contain '0' and '1'.
Exceptions
std::invalid_argumentif any character is not '0' or '1'.

The char literal is expected to be null-terminated (asserted in debug-mode). If it is not, the last character will be lost when copying to the instance of dynamic_bitset.

Complexity

Linear in the size of lit.

Exceptions

Throws std::invalid_argument if any character is not '0' or '1'.

◆ assign() [3/5]

template<size_t bit_capacity = 58>
template<std::ranges::input_range other_range_t>
requires std::constructible_from<value_type, std::ranges::range_reference_t<other_range_t>>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::assign ( other_range_t &&  range)
inlineconstexprnoexcept

Assign from a different range.

Template Parameters
other_range_tThe type of range to be inserted; must satisfy std::ranges::input_range and value_type must be constructible from std::ranges::range_reference_t<other_range_t>.
Parameters
[in]rangeThe sequences to construct/assign from.

Complexity

Linear in the size of range.

Exceptions

No-throw guarantee.

◆ assign() [4/5]

template<size_t bit_capacity = 58>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::assign ( size_type const  count,
value_type const  value 
)
inlineconstexprnoexcept

Assign with count times value.

Parameters
[in]countNumber of elements.
[in]valueThe initial value to be assigned.

Complexity

Linear in count.

Exceptions

No-throw guarantee.

◆ assign() [5/5]

template<size_t bit_capacity = 58>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::assign ( std::initializer_list< value_type > const  ilist)
inlineconstexprnoexcept

Assign from std::initializer_list.

Parameters
[in]ilistA std::initializer_list of value_type.

Complexity

Linear in the size of ilist.

Exceptions

No-throw guarantee.

◆ at() [1/2]

template<size_t bit_capacity = 58>
constexpr reference bio::ranges::dynamic_bitset< bit_capacity >::at ( size_t const  i)
inlineconstexpr

Returns the i-th element.

Parameters
[in]iIndex of the element to retrieve.
Exceptions
std::out_of_rangeIf you access an element behind the last.
Returns
A reference to the value at position i.

Complexity

Constant.

Exceptions

Throws std::out_of_range if i >= size().

◆ at() [2/2]

template<size_t bit_capacity = 58>
constexpr const_reference bio::ranges::dynamic_bitset< bit_capacity >::at ( size_t const  i) const
inlineconstexpr

Returns the i-th element.

Parameters
[in]iIndex of the element to retrieve.
Exceptions
std::out_of_rangeIf you access an element behind the last.
Returns
A reference to the value at position i.

Complexity

Constant.

Exceptions

Throws std::out_of_range if i >= size().

◆ back() [1/2]

template<size_t bit_capacity = 58>
constexpr const_reference bio::ranges::dynamic_bitset< bit_capacity >::back ( ) const
inlineconstexprnoexcept

Returns the last element.

Returns
A reference to the value at the last position.

Calling back() on an empty container is undefined. In debug mode an assertion checks the size of the container.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ back() [2/2]

template<size_t bit_capacity = 58>
constexpr reference bio::ranges::dynamic_bitset< bit_capacity >::back ( )
inlineconstexprnoexcept

Returns the last element.

Returns
A reference to the value at the last position.

Calling back() on an empty container is undefined. In debug mode an assertion checks the size of the container.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ begin() [1/2]

template<size_t bit_capacity = 58>
constexpr const_iterator bio::ranges::dynamic_bitset< bit_capacity >::begin ( ) const
inlineconstexprnoexcept

Returns the begin to the dynamic_bitset.

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
fmt::print("{}", *it); // 111100011101
fmt::print("\n");
}

◆ begin() [2/2]

template<size_t bit_capacity = 58>
constexpr iterator bio::ranges::dynamic_bitset< bit_capacity >::begin ( )
inlineconstexprnoexcept

Returns the begin to the dynamic_bitset.

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
fmt::print("{}", *it); // 111100011101
fmt::print("\n");
}

◆ capacity()

template<size_t bit_capacity = 58>
constexpr size_type bio::ranges::dynamic_bitset< bit_capacity >::capacity ( ) const
inlineconstexprnoexcept

Returns the number of elements that the container is able to hold and resolves to bit_capacity.

Returns
The capacity of the currently allocated storage.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ cbegin()

template<size_t bit_capacity = 58>
constexpr const_iterator bio::ranges::dynamic_bitset< bit_capacity >::cbegin ( ) const
inlineconstexprnoexcept

Returns the begin to the dynamic_bitset.

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
fmt::print("{}", *it); // 111100011101
fmt::print("\n");
}

◆ cend()

template<size_t bit_capacity = 58>
constexpr const_iterator bio::ranges::dynamic_bitset< bit_capacity >::cend ( ) const
inlineconstexprnoexcept

Returns iterator past the end of the dynamic_bitset.

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
fmt::print("{}", *it); // 111100011101
fmt::print("\n");
}

◆ clear()

template<size_t bit_capacity = 58>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::clear ( )
inlineconstexprnoexcept

Removes all elements from the container.

Attention
In contrast to reset(), this method also sets the size to 0.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ empty()

template<size_t bit_capacity = 58>
constexpr bool bio::ranges::dynamic_bitset< bit_capacity >::empty ( ) const
inlineconstexprnoexcept

Checks whether the container is empty.

Returns
true if the container is empty, false otherwise.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ end() [1/2]

template<size_t bit_capacity = 58>
constexpr const_iterator bio::ranges::dynamic_bitset< bit_capacity >::end ( ) const
inlineconstexprnoexcept

Returns iterator past the end of the dynamic_bitset.

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
fmt::print("{}", *it); // 111100011101
fmt::print("\n");
}

◆ end() [2/2]

template<size_t bit_capacity = 58>
constexpr iterator bio::ranges::dynamic_bitset< bit_capacity >::end ( )
inlineconstexprnoexcept

Returns iterator past the end of the dynamic_bitset.

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
fmt::print("{}", *it); // 111100011101
fmt::print("\n");
}

◆ erase() [1/2]

template<size_t bit_capacity = 58>
constexpr iterator bio::ranges::dynamic_bitset< bit_capacity >::erase ( const_iterator  begin_it,
const_iterator  end_it 
)
inlineconstexprnoexcept

Removes specified elements from the container.

Parameters
[in]begin_itBegin of range to erase.
[in]end_itBehind the end of range to erase.
Returns
Iterator following the last element removed. If the iterator pos refers to the last element, the end() iterator is returned.

Invalidates iterators and references at or after the point of the erase, including the end() iterator.

The iterator begin_it does not need to be dereferenceable if begin_it==end_it: erasing an empty range is a no-op.

Complexity

Linear in size().

Exceptions

No-throw guarantee.

◆ erase() [2/2]

template<size_t bit_capacity = 58>
constexpr iterator bio::ranges::dynamic_bitset< bit_capacity >::erase ( const_iterator  pos)
inlineconstexprnoexcept

Removes specified elements from the container.

Parameters
[in]posRemove the element at pos.
Returns
Iterator following the last element removed. If the iterator pos refers to the last element, the end() iterator is returned.

Invalidates iterators and references at or after the point of the erase, including the end() iterator.

The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferencable) cannot be used as a value for pos.

Complexity

Linear in size().

Exceptions

No-throw guarantee.

◆ flip() [1/2]

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::flip ( )
inlineconstexprnoexcept

Flips all bits (binary NOT).

Returns
*this

Example

int main()
{
t1.flip();
fmt::print("{}\n", t1); // 0111'0011
}
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition: dynamic_bitset.hpp:861

Exception

No-throw guarantee.

Complexity

Constant.

◆ flip() [2/2]

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::flip ( size_t const  i)
inlineconstexpr

Flips the i'th bit (binary NOT).

Parameters
[in]iIndex of the bit to flip.
Exceptions
std::out_of_rangeif you access an element behind the last.
Returns
*this

Example

int main()
{
t1.flip(0);
t1.flip(3);
fmt::print("{}\n", t1); // 1000'0101
}

Exception

Throws std::out_of_range if i >= size().

Complexity

Constant.

◆ front() [1/2]

template<size_t bit_capacity = 58>
constexpr const_reference bio::ranges::dynamic_bitset< bit_capacity >::front ( ) const
inlineconstexprnoexcept

Returns the first element.

Returns
A reference to the value at the first position.

Calling front() on an empty container is undefined. In debug mode an assertion checks the size of the container.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ front() [2/2]

template<size_t bit_capacity = 58>
constexpr reference bio::ranges::dynamic_bitset< bit_capacity >::front ( )
inlineconstexprnoexcept

Returns the first element.

Returns
A reference to the value at the first position.

Calling front() on an empty container is undefined. In debug mode an assertion checks the size of the container.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ insert() [1/4]

template<size_t bit_capacity = 58>
template<std::forward_iterator begin_it_type, typename end_it_type >
requires (std::sentinel_for<end_it_type, begin_it_type> && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
constexpr iterator bio::ranges::dynamic_bitset< bit_capacity >::insert ( const_iterator  pos,
begin_it_type  begin_it,
end_it_type  end_it 
)
inlineconstexprnoexcept

Inserts elements from range [begin_it, end_it) before pos in the container.

Template Parameters
begin_it_typeMust model std::forward_iterator and the value_type must be constructible from the reference type of begin_it_type.
end_it_typeMust model std::sentinel_for.
Parameters
[in]posIterator before which the content will be inserted. pos may be the end() iterator.
[in]begin_itBegin of range to construct/assign from.
[in]end_itEnd of range to construct/assign from.
Returns
Iterator pointing to the first element inserted, or pos if begin_it==end_it.

The behaviour is undefined if begin_it and end_it are iterators into *this or if, given the size n of the range represented by [begin_t, end_it), size() + n > capacity().

Complexity

Worst-case linear in size().

Exceptions

No-throw guarantee.

◆ insert() [2/4]

template<size_t bit_capacity = 58>
constexpr iterator bio::ranges::dynamic_bitset< bit_capacity >::insert ( const_iterator  pos,
size_type const  count,
value_type const  value 
)
inlineconstexprnoexcept

Inserts count copies of value before position in the container.

Parameters
[in]posIterator before which the content will be inserted. pos may be the end() iterator.
[in]countNumber of copies.
[in]valueElement value to insert.
Returns
Iterator pointing to the first element inserted, or pos if count==0.

If size() + count > capacity() this function results in undefined behaviour.

Complexity

Worst-case linear in size().

Exceptions

No-throw guarantee.

◆ insert() [3/4]

template<size_t bit_capacity = 58>
constexpr iterator bio::ranges::dynamic_bitset< bit_capacity >::insert ( const_iterator  pos,
std::initializer_list< value_type > const &  ilist 
)
inlineconstexprnoexcept

Inserts elements from initializer list before pos in the container.

Parameters
[in]posIterator before which the content will be inserted. pos may be the end() iterator.
[in]ilistInitializer list with values to insert.
Returns
Iterator pointing to the first element inserted, or pos if ilist is empty.

Given the size n of ilist, this function results in undefined behaviour if size() + n > capacity().

Complexity

Worst-case linear in size().

Exceptions

No-throw guarantee.

◆ insert() [4/4]

template<size_t bit_capacity = 58>
constexpr iterator bio::ranges::dynamic_bitset< bit_capacity >::insert ( const_iterator  pos,
value_type const  value 
)
inlineconstexprnoexcept

Inserts value before pos in the container.

Parameters
[in]posIterator before which the content will be inserted. pos may be the end() iterator.
[in]valueElement value to insert.
Returns
Iterator pointing to the inserted value.

Inserting a value although the maximum capacity is reached is undefined behaviour.

Complexity

Worst-case linear in size().

Exceptions

No-throw guarantee.

◆ max_size()

template<size_t bit_capacity = 58>
constexpr size_type bio::ranges::dynamic_bitset< bit_capacity >::max_size ( ) const
inlineconstexprnoexcept

Returns the maximum number of elements the container is able to hold and resolves to bit_capacity.

Returns
The number of elements in the container.

This value typically reflects the theoretical limit on the size of the container. At runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available.

For the dynamic_bitset holds: max_size() = capacity().

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ none()

template<size_t bit_capacity = 58>
constexpr bool bio::ranges::dynamic_bitset< bit_capacity >::none ( ) const
inlineconstexprnoexcept

Checks if no bit is set.

Returns
true if no bit is set, false otherwise.

◆ operator&=()

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::operator&= ( dynamic_bitset< bit_capacity > const &  rhs)
inlineconstexprnoexcept

Sets the bits to the result of binary AND on corresponding pairs of bits of *this and rhs.

Parameters
[in]rhsdynamic_bitset to perform binary AND with.
Returns
*this
Attention
Both dynamic_bitsets must have the same size. In debug mode an assertion checks this constraint.

Example

int main()
{
bio::ranges::dynamic_bitset const t2{0b1011'1000};
t1 &= t2;
fmt::print("{}\n", t1); // 1000'1000
}

Exception

No-throw guarantee.

Complexity

Constant.

◆ operator<<()

template<size_t bit_capacity = 58>
constexpr dynamic_bitset bio::ranges::dynamic_bitset< bit_capacity >::operator<< ( size_t const  count) const
inlineconstexprnoexcept

Performs binary shift left.

Parameters
[in]countAmount to shift to the left.
Returns
Copy of *this with bits shifted count to the left.

Example

int main()
{
bio::ranges::dynamic_bitset const t1{"10001100"};
fmt::print("{}\n", t2); // 0110'0000
}

Exception

No-throw guarantee.

Complexity

Constant.

◆ operator<<=()

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::operator<<= ( size_t const  count)
inlineconstexprnoexcept

Performs binary shift left on the current object.

Parameters
[in]countAmount to shift to the left.
Returns
*this

Example

int main()
{
t1 <<= 3;
fmt::print("{}\n", t1); // 0110'0000
}

Exception

No-throw guarantee.

Complexity

Constant.

◆ operator=() [1/2]

template<size_t bit_capacity = 58>
template<size_t N>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::operator= ( char const (&)  lit[N])
inlineconstexpr

Assign from literal.

Parameters
[in]litThe literal to assign the string from. May only contain '0' and '1'.
Exceptions
std::invalid_argumentif any character is not '0' or '1'.

The char literal is expected to be null-terminated (asserted in debug-mode). If it is not, the last character will be lost when copying to the instance of dynamic_bitset.

Complexity

Linear in the size of lit.

Exceptions

Throws std::invalid_argument if any character is not '0' or '1'.

◆ operator=() [2/2]

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::operator= ( std::initializer_list< value_type > const  ilist)
inlineconstexprnoexcept

Assign from std::initializer_list.

Parameters
[in]ilistA std::initializer_list of value_type.

Complexity

Linear in the size of ilist.

Exceptions

No-throw guarantee.

◆ operator>>()

template<size_t bit_capacity = 58>
constexpr dynamic_bitset bio::ranges::dynamic_bitset< bit_capacity >::operator>> ( size_t const  count) const
inlineconstexprnoexcept

Performs binary shift right.

Parameters
[in]countAmount to shift to the right.
Returns
Copy of *this with bits shifted count to the right.

Example

int main()
{
bio::ranges::dynamic_bitset const t1{"10001100"};
fmt::print("{}\n", t2); // 0001'0001
}

Exception

No-throw guarantee.

Complexity

Constant.

◆ operator>>=()

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::operator>>= ( size_t const  count)
inlineconstexprnoexcept

Performs binary shift right on the current object.

Parameters
[in]countAmount to shift to the right.
Returns
*this

Example

int main()
{
t1 >>= 3;
fmt::print("{}\n", t1); // 0001'0001
}

Exception

No-throw guarantee.

Complexity

Constant.

◆ operator[]() [1/2]

template<size_t bit_capacity = 58>
constexpr const_reference bio::ranges::dynamic_bitset< bit_capacity >::operator[] ( size_t const  i) const
inlineconstexprnoexcept

Returns the i-th element.

Parameters
[in]iThe element to retrieve.
Returns
A reference to the value at position i.

Accessing an element behind the last causes undefined behaviour. In debug mode an assertion checks the size of the container.

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111};
// Positions are 0-based and start at the rightmost bit.
for (size_t i = 0; i < t1.size(); ++i)
fmt::print("{}", t1[i]); // 1111'0001'1101
fmt::print("{}", '\n');
}

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ operator[]() [2/2]

template<size_t bit_capacity = 58>
constexpr reference bio::ranges::dynamic_bitset< bit_capacity >::operator[] ( size_t const  i)
inlineconstexprnoexcept

Returns the i-th element.

Parameters
[in]iThe element to retrieve.
Returns
A reference to the value at position i.

Accessing an element behind the last causes undefined behaviour. In debug mode an assertion checks the size of the container.

Example

int main()
{
bio::ranges::dynamic_bitset t1{0b1011'1000'1111};
// Positions are 0-based and start at the rightmost bit.
for (size_t i = 0; i < t1.size(); ++i)
fmt::print("{}", t1[i]); // 1111'0001'1101
fmt::print("{}", '\n');
}

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ operator^=()

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::operator^= ( dynamic_bitset< bit_capacity > const &  rhs)
inlineconstexprnoexcept

Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and rhs.

Parameters
[in]rhsdynamic_bitset to perform binary XOR with.
Returns
*this
Attention
Both dynamic_bitsets must have the same size. In debug mode an assertion checks this constraint.

Example

int main()
{
bio::ranges::dynamic_bitset const t2{0b1011'1000};
t1 ^= t2;
fmt::print("{}\n", t1); // 0011'0100
}

Exception

No-throw guarantee.

Complexity

Constant.

◆ operator|=()

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::operator|= ( dynamic_bitset< bit_capacity > const &  rhs)
inlineconstexprnoexcept

Sets the bits to the result of binary OR on corresponding pairs of bits of *this and rhs.

Parameters
[in]rhsdynamic_bitset to perform binary OR with.
Returns
*this
Attention
Both dynamic_bitsets must have the same size. In debug mode an assertion checks this constraint.

Example

int main()
{
bio::ranges::dynamic_bitset const t2{0b1011'1000};
t1 |= t2;
fmt::print("{}\n", t1); // 1011'1100
}

Exception

No-throw guarantee.

Complexity

Constant.

◆ operator~()

template<size_t bit_capacity = 58>
constexpr dynamic_bitset bio::ranges::dynamic_bitset< bit_capacity >::operator~ ( ) const
inlineconstexprnoexcept

Returns a temporary copy of *this with all bits flipped (binary NOT).

Returns
Copy of *this with all bits flipped.

Example

int main()
{
bio::ranges::dynamic_bitset const t1{"10001100"};
fmt::print("{}\n", t2); // 0111'0011
}

Exception

No-throw guarantee.

Thread-safety

Thread safe.

Complexity

Constant.

◆ pop_back()

template<size_t bit_capacity = 58>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::pop_back ( )
inlineconstexprnoexcept

Removes the last element of the container.

Calling pop_back() on an empty container is undefined. In debug mode an assertion will be thrown.

No iterators or references except for back() and end() are invalidated.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ push_back()

template<size_t bit_capacity = 58>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::push_back ( value_type const  value)
inlineconstexprnoexcept

Appends the given element value to the end of the container.

Parameters
[in]valueThe value to append.

If the new size() is greater than capacity() this is undefined behaviour.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ raw_data()

template<size_t bit_capacity = 58>
constexpr detail::dynamic_bitset_bitfield const * bio::ranges::dynamic_bitset< bit_capacity >::raw_data ( ) const
inlineconstexprnoexcept

Direct access to the underlying bit field.

◆ reset() [1/2]

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::reset ( )
inlineconstexprnoexcept

Sets all bits to 0.

Returns
*this
Attention
In contrast to clear(), this method does not modify the size.

Example

int main()
{
t1.reset();
fmt::print("{}\n", t1); // 0000'0000
}
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition: dynamic_bitset.hpp:813

Exception

No-throw guarantee.

Complexity

Constant.

◆ reset() [2/2]

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::reset ( size_t const  i)
inlineconstexpr

Sets the i'th bit to false.

Parameters
[in]iIndex of the bit to reset.
Exceptions
std::out_of_rangeif you access an element behind the last.
Returns
*this

Example

int main()
{
t1.reset(2);
t1.reset(3);
fmt::print("{}\n", t1); // 1000'0000
}

Exception

Throws std::out_of_range if i >= size().

Complexity

Constant.

◆ resize()

template<size_t bit_capacity = 58>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::resize ( size_type const  count,
value_type const  value = false 
)
inlineconstexprnoexcept

Resizes the container to contain count elements.

Parameters
[in]countThe new size.
[in]valueAppend copies of value when resizing, default = false.

If count is greater than capacity() this is undefined behaviour. If the dynamic_bitset is enlarged, bits in [0, size()) stay the same and bits in [size(), count) are set to value. If the dynamic_bitset is shrunk, bits in [0, count) stay the same and bits in [count, size()) are set to 0.

Example

int main()
{
t1.resize(8); // Enlarge to 8.
fmt::print("{}\n", t1); // 0000'1100
t1.resize(5); // Shrink to 5, last three bits (5, 6, 7) are set to false.
fmt::print("{}\n", t1); // 0110'0
t1.resize(10, true); // Enlarge to 10 and set new bits to true.
fmt::print("{}\n", t1); // 1111'1011'00
}
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition: dynamic_bitset.hpp:1390

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ set() [1/2]

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::set ( )
inlineconstexprnoexcept

Sets all bits to 1.

Returns
*this

Example

int main()
{
t1.set();
fmt::print("{}\n", t1); // 1111'1111
}
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition: dynamic_bitset.hpp:761

Exception

No-throw guarantee.

Complexity

Constant.

◆ set() [2/2]

template<size_t bit_capacity = 58>
constexpr dynamic_bitset & bio::ranges::dynamic_bitset< bit_capacity >::set ( size_t const  i,
bool const  value = true 
)
inlineconstexpr

Sets the i'th bit to value.

Parameters
[in]iIndex of the bit to set.
[in]valueValue to set. Default true.
Exceptions
std::out_of_rangeif you access an element behind the last.
Returns
*this

Example

int main()
{
t1.set(0);
t1.set(2, false);
fmt::print("{}\n", t1); // 1000'1001
}

Exception

Throws std::out_of_range if i >= size().

Complexity

Constant.

◆ size()

template<size_t bit_capacity = 58>
constexpr size_type bio::ranges::dynamic_bitset< bit_capacity >::size ( ) const
inlineconstexprnoexcept

Returns the number of elements in the container, i.e. std::distance(begin(), end()).

Returns
The number of elements in the container.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ swap()

template<size_t bit_capacity = 58>
constexpr void bio::ranges::dynamic_bitset< bit_capacity >::swap ( dynamic_bitset< bit_capacity > &  rhs)
inlineconstexprnoexcept

Swap contents with another instance.

Parameters
[in]rhsThe other instance to swap with.

Complexity

Linear in the size of both containers.

Exceptions

No-throw guarantee if value_type is std::is_nothrow_copy_constructible.

◆ test()

template<size_t bit_capacity = 58>
constexpr const_reference bio::ranges::dynamic_bitset< bit_capacity >::test ( size_t const  i) const
inlineconstexpr

Returns the i-th element.

Parameters
[in]iIndex of the element to retrieve.
Exceptions
std::out_of_rangeIf you access an element behind the last.
Returns
A reference to the value at position i.

Complexity

Constant.

Exceptions

Throws std::out_of_range if i >= size().

◆ to_ullong()

template<size_t bit_capacity = 58>
constexpr unsigned long long bio::ranges::dynamic_bitset< bit_capacity >::to_ullong ( ) const
inlineconstexpr

Converts the dynamic_bitset to an unsigned long long integer.

Exceptions
std::overflow_errorif the value cannot be represented in unsigned long long.
Returns
A unsigned long long representing the dynamic_bitset.

Complexity

Constant.

Exceptions

Throws std::overflow_error if the value cannot be represented in unsigned long long.

◆ to_ulong()

template<size_t bit_capacity = 58>
constexpr unsigned long bio::ranges::dynamic_bitset< bit_capacity >::to_ulong ( ) const
inlineconstexpr

Converts the dynamic_bitset to an unsigned long integer.

Exceptions
std::overflow_errorif the value cannot be represented in unsigned long.
Returns
A unsigned long representing the dynamic_bitset.

Complexity

Constant.

Exceptions

Throws std::overflow_error if the value cannot be represented in unsigned long.

Friends And Related Function Documentation

◆ operator&

template<size_t bit_capacity = 58>
template<size_t cap>
requires (cap <= bit_capacity)
constexpr dynamic_bitset operator& ( dynamic_bitset< bit_capacity > const &  lhs,
dynamic_bitset< cap > const &  rhs 
)
friend

Returns dynamic_bitset containing the result of binary AND on corresponding pairs of bits of lhs and rhs.

Attention
Both dynamic_bitsets must have the same size. In debug mode an assertion checks this constraint.

◆ operator^

template<size_t bit_capacity = 58>
template<size_t cap>
requires (cap <= bit_capacity)
constexpr dynamic_bitset operator^ ( dynamic_bitset< bit_capacity > const &  lhs,
dynamic_bitset< cap > const &  rhs 
)
friend

Returns dynamic_bitset containing the result of binary XOR on corresponding pairs of bits of lhs and rhs.

Attention
Both dynamic_bitsets must have the same size. In debug mode an assertion checks this constraint.

◆ operator|

template<size_t bit_capacity = 58>
template<size_t cap>
requires (cap <= bit_capacity)
constexpr dynamic_bitset operator| ( dynamic_bitset< bit_capacity > const &  lhs,
dynamic_bitset< cap > const &  rhs 
)
friend

Returns dynamic_bitset containing the result of binary OR on corresponding pairs of bits of lhs and rhs.

Attention
Both dynamic_bitsets must have the same size. In debug mode an assertion checks this constraint.

◆ swap

template<size_t bit_capacity = 58>
constexpr void swap ( dynamic_bitset< bit_capacity > &  lhs,
dynamic_bitset< bit_capacity > &  rhs 
)
friend

Swap contents with another instance.

Parameters
[in]lhsThe first instance.
[in]rhsThe other instance to swap with.

Complexity

Linear in the size of both containers.

Exceptions

No-throw guarantee if value_type is std::is_nothrow_copy_constructible.


The documentation for this class was generated from the following file: