Loading...
Searching...
No Matches
seqan3::dynamic_bitset< bit_capacity > Class Template Reference
Utility » Container

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

`#include <seqan3/utility/container/dynamic_bitset.hpp>`

Inheritance diagram for seqan3::dynamic_bitset< bit_capacity >:
[legend]

## Public Types

Associated types
using | value_type = bool
| Equals bool.
using | reference = reference_proxy_type
| 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 = 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_bitset & | operator= (dynamic_bitset const &) noexcept=default
| Defaulted.
constexpr dynamic_bitset & | operator= (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<std::ranges::input_range other_range_t> requires (!std::same_as<std::remove_cvref_t<other_range_t>, dynamic_bitset>)
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_bitset & | operator= (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_bitset & | operator= (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_bitset & | operator&= (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_bitset & | operator|= (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_bitset & | operator^= (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_bitset & | operator<<= (size_t const count) noexcept
| Performs binary shift left on the current object.
constexpr dynamic_bitset & | operator>>= (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_bitset & | set () noexcept
| Sets all bits to 1.
constexpr dynamic_bitset & | set (size_t const i, bool const value=true)
| Sets the i'th bit to value.
constexpr dynamic_bitset & | reset () noexcept
| Sets all bits to 0.
constexpr dynamic_bitset & | reset (size_t const i)
| Sets the i'th bit to false.
constexpr dynamic_bitset & | flip () noexcept
| Flips all bits (binary NOT).
constexpr dynamic_bitset & | flip (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 bitfield * | raw_data () noexcept
| Direct access to the underlying bit field.
constexpr 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
template<typename char_t = char>
std::string | to_string (char_t zero=char_t{ '0'}, char_t one=char_t{ '1'}) const
| Converts the dynamic_bitset to a std::string.
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 bool | operator!= (dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
| Performs element-wise comparison.
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 bool | operator> (dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
| Performs element-wise comparison.
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 bool | operator>= (dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
| Performs element-wise comparison.
Input/output
std::ostream & | operator<< (std::ostream &os, dynamic_bitset const &arg)
| Formatted output for the seqan3::dynamic_bitset.
std::istream & | operator>> (std::istream &is, dynamic_bitset &arg)
| Formatted input for the seqan3::dynamic_bitset.

## Detailed Description

template<size_t bit_capacity = 58>
class seqan3::dynamic_bitset< bit_capacity >

A constexpr bitset implementation with dynamic size at compile time.

Template Parameters

  bit_capacity | The 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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"}; // Construct from string.
seqan3::dynamic_bitset const t2{0b1011'1000}; // Construct from binary literal or integer.
seqan3::debug_stream << t1 << '\n'; // Debug printing inserts separators: 1000'1100
std::cout << t2 << '\n'; // Standard printing does not: 10111000
t1 &= t2; // Assign t1 the result of a binary AND of t1 and t2.
seqan3::debug_stream << t1 << '\n'; // 1000'1000
}
seqan3::dynamic_bitset
A constexpr bitset implementation with dynamic size at compile time.
Definition dynamic_bitset.hpp:53
std::cout
debug_stream.hpp
Provides seqan3::debug_stream and related types.
dynamic_bitset.hpp
A constexpr bitset implementation with dynamic size at compile time.
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:38

### 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).

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## Member Typedef Documentation

## const_iterator

template<size_t bit_capacity = 58>

using seqan3::dynamic_bitset< bit_capacity >::const_iterator = detail::random_access_iterator<dynamic_bitset const>

The const_iterator type of this container (a random access iterator).

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## const_reference

template<size_t bit_capacity = 58>

using seqan3::dynamic_bitset< bit_capacity >::const_reference = bool

Equals the value_type.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## difference_type

template<size_t bit_capacity = 58>

using seqan3::dynamic_bitset< bit_capacity >::difference_type = ptrdiff_t

A std::ptrdiff_t.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## iterator

template<size_t bit_capacity = 58>

using seqan3::dynamic_bitset< bit_capacity >::iterator = detail::random_access_iterator<dynamic_bitset>

The iterator type of this container (a random access iterator).

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## reference

template<size_t bit_capacity = 58>

using seqan3::dynamic_bitset< bit_capacity >::reference = reference_proxy_type

A proxy type that enables assignment.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## size_type

template<size_t bit_capacity = 58>

using seqan3::dynamic_bitset< bit_capacity >::size_type = detail::min_viable_uint_t<bit_capacity>

An unsigned integer type (usually std::size_t).

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## value_type

template<size_t bit_capacity = 58>

using seqan3::dynamic_bitset< bit_capacity >::value_type = bool

Equals bool.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## Constructor & Destructor Documentation

## dynamic_bitset() [1/5]

template<size_t bit_capacity = 58>

seqan3::dynamic_bitset< bit_capacity >::dynamic_bitset | ( | uint64_t const | value | ) |

inline constexpr

Construct from an uint64_t.

Parameters

  [in] | value | The uint64_t to construct/assign from.

Exceptions

  std::invalid_argument | if value has bits set outside of [0, 58).

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111}; // Use binary literal.
seqan3::dynamic_bitset t2{0b0000'1000'1111}; // Leading zeros are stripped.
seqan3::dynamic_bitset t3{832}; // Use a number.
seqan3::debug_stream << t1 << '\n'; // 1011'1000'1111
seqan3::debug_stream << t2 << '\n'; // 1000'1111
seqan3::debug_stream << t3 << '\n'; // 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## 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>>

seqan3::dynamic_bitset< bit_capacity >::dynamic_bitset | ( | begin_it_type | begin_it,
|  | end_it_type | end_it )

inline constexpr noexcept

Construct from two iterators.

Template Parameters

  begin_it_type | Must model std::forward_iterator and value_type must be constructible from the reference type of begin_it_type.
  end_it_type | Must model std::sentinel_for.

Parameters

  [in] | begin_it | Begin of range to construct/assign from.
  [in] | end_it | End of range to construct/assign from.

### Complexity

Linear in the distance between begin_it and end_it.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## dynamic_bitset() [3/5]

template<size_t bit_capacity = 58>
template<std::ranges::input_range other_range_t>
requires (!std::same_as<std::remove_cvref_t<other_range_t>, dynamic_bitset>)

seqan3::dynamic_bitset< bit_capacity >::dynamic_bitset | ( | other_range_t && | range | ) |

inline explicit constexpr noexcept

Construct from a different range.

Template Parameters

  other_range_t | The 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] | range | The sequence to construct/assign from.

### Complexity

Linear in the size of range.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1. This is a non-standard C++ extension.

## dynamic_bitset() [4/5]

template<size_t bit_capacity = 58>

seqan3::dynamic_bitset< bit_capacity >::dynamic_bitset | ( | size_type const | n,
|  | value_type const | value )

inline constexpr noexcept

Construct with n times value.

Parameters

  [in] | n | Number of elements.
  [in] | value | The initial value to be assigned.

### Complexity

Linear in n.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## dynamic_bitset() [5/5]

template<size_t bit_capacity = 58>
template<size_t N>

seqan3::dynamic_bitset< bit_capacity >::dynamic_bitset | ( | char const (&) | lit[N] | ) |

inline constexpr

Construction from literal.

Parameters

  [in] | lit | The literal to construct the string for. May only contain `'0'` and `'1'`.

Exceptions

  std::invalid_argument | if 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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"101110001111"}; // Use character literal.
seqan3::dynamic_bitset t2{"000010001111"}; // Leading zeros are kept.
seqan3::debug_stream << t1 << '\n'; // 1011'1000'1111
seqan3::debug_stream << t2 << '\n'; // 0000'1000'1111
}

### Complexity

Linear in the size of lit.

### Exceptions

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

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## Member Function Documentation

## all()

template<size_t bit_capacity = 58>

bool seqan3::dynamic_bitset< bit_capacity >::all | ( |  | ) | const

inline constexpr noexcept

Checks if all bit are set.

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

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## any()

template<size_t bit_capacity = 58>

bool seqan3::dynamic_bitset< bit_capacity >::any | ( |  | ) | const

inline constexpr noexcept

Checks if any bit is set.

Returns
  true if any bit is set, false otherwise.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## 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>>

void seqan3::dynamic_bitset< bit_capacity >::assign | ( | begin_it_type | begin_it,
|  | end_it_type | end_it )

inline constexpr noexcept

Assign from pair of iterators.

Template Parameters

  begin_it_type | Must model std::forward_iterator and the value_type must be constructible from the reference type of begin_it_type.
  end_it_type | Must model std::sentinel_for.

Parameters

  [in] | begin_it | Begin of range to construct/assign from.
  [in] | end_it | End of range to construct/assign from.

### Complexity

Linear in the distance between begin_it and end_it.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## assign() [2/5]

template<size_t bit_capacity = 58>
template<size_t N>

void seqan3::dynamic_bitset< bit_capacity >::assign | ( | char const (&) | lit[N] | ) |

inline constexpr

Assign from literal.

Parameters

  [in] | lit | The literal to assign the string from. May only contain `'0'` and `'1'`.

Exceptions

  std::invalid_argument | if 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'`.

This entity is experimental and subject to change in the future. Experimental since version 3.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>>

void seqan3::dynamic_bitset< bit_capacity >::assign | ( | other_range_t && | range | ) |

inline constexpr noexcept

Assign from a different range.

Template Parameters

  other_range_t | The 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] | range | The sequences to construct/assign from.

### Complexity

Linear in the size of range.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1. This is a non-standard C++ extension.

## assign() [4/5]

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::assign | ( | size_type const | count,
|  | value_type const | value )

inline constexpr noexcept

Assign with count times value.

Parameters

  [in] | count | Number of elements.
  [in] | value | The initial value to be assigned.

### Complexity

Linear in count.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## assign() [5/5]

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::assign | ( | std::initializer_list< value_type > const | ilist | ) |

inline constexpr noexcept

Assign from std::initializer_list.

Parameters

  [in] | ilist | A std::initializer_list of value_type.

### Complexity

Linear in the size of ilist.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## at() [1/2]

template<size_t bit_capacity = 58>

reference seqan3::dynamic_bitset< bit_capacity >::at | ( | size_t const | i | ) |

inline constexpr

Returns the i-th element.

Parameters

  [in] | i | Index of the element to retrieve.

Exceptions

  std::out_of_range | If 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().

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## at() [2/2]

template<size_t bit_capacity = 58>

const_reference seqan3::dynamic_bitset< bit_capacity >::at | ( | size_t const | i | ) | const

inline constexpr

Returns the i-th element.

Parameters

  [in] | i | Index of the element to retrieve.

Exceptions

  std::out_of_range | If 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().

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## back() [1/2]

template<size_t bit_capacity = 58>

const_reference seqan3::dynamic_bitset< bit_capacity >::back | ( |  | ) | const

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## back() [2/2]

template<size_t bit_capacity = 58>

reference seqan3::dynamic_bitset< bit_capacity >::back | ( |  | ) |

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## begin() [1/2]

template<size_t bit_capacity = 58>

const_iterator seqan3::dynamic_bitset< bit_capacity >::begin | ( |  | ) | const

inline constexpr noexcept

Returns the begin to the dynamic_bitset.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
seqan3::debug_stream << *it; // 1111'0001'1101
seqan3::debug_stream << '\n';
}
seqan3::dynamic_bitset::end
constexpr iterator end() noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:581
seqan3::dynamic_bitset::begin
constexpr iterator begin() noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:554

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## begin() [2/2]

template<size_t bit_capacity = 58>

iterator seqan3::dynamic_bitset< bit_capacity >::begin | ( |  | ) |

inline constexpr noexcept

Returns the begin to the dynamic_bitset.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
seqan3::debug_stream << *it; // 1111'0001'1101
seqan3::debug_stream << '\n';
}

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## capacity()

template<size_t bit_capacity = 58>

size_type seqan3::dynamic_bitset< bit_capacity >::capacity | ( |  | ) | const

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## cbegin()

template<size_t bit_capacity = 58>

const_iterator seqan3::dynamic_bitset< bit_capacity >::cbegin | ( |  | ) | const

inline constexpr noexcept

Returns the begin to the dynamic_bitset.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
seqan3::debug_stream << *it; // 1111'0001'1101
seqan3::debug_stream << '\n';
}

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## cend()

template<size_t bit_capacity = 58>

const_iterator seqan3::dynamic_bitset< bit_capacity >::cend | ( |  | ) | const

inline constexpr noexcept

Returns iterator past the end of the dynamic_bitset.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
seqan3::debug_stream << *it; // 1111'0001'1101
seqan3::debug_stream << '\n';
}

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## clear()

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::clear | ( |  | ) |

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## count()

template<size_t bit_capacity = 58>

size_type seqan3::dynamic_bitset< bit_capacity >::count | ( |  | ) | const

inline constexpr noexcept

Returns the number of set bits.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## empty()

template<size_t bit_capacity = 58>

bool seqan3::dynamic_bitset< bit_capacity >::empty | ( |  | ) | const

inline constexpr noexcept

Checks whether the container is empty.

Returns
  true if the container is empty, false otherwise.

### Complexity

Constant.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## end() [1/2]

template<size_t bit_capacity = 58>

const_iterator seqan3::dynamic_bitset< bit_capacity >::end | ( |  | ) | const

inline constexpr noexcept

Returns iterator past the end of the dynamic_bitset.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
seqan3::debug_stream << *it; // 1111'0001'1101
seqan3::debug_stream << '\n';
}

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## end() [2/2]

template<size_t bit_capacity = 58>

iterator seqan3::dynamic_bitset< bit_capacity >::end | ( |  | ) |

inline constexpr noexcept

Returns iterator past the end of the dynamic_bitset.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
seqan3::debug_stream << *it; // 1111'0001'1101
seqan3::debug_stream << '\n';
}

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## erase() [1/2]

template<size_t bit_capacity = 58>

iterator seqan3::dynamic_bitset< bit_capacity >::erase | ( | const_iterator | begin_it,
|  | const_iterator | end_it )

inline constexpr noexcept

Removes specified elements from the container.

Parameters

  [in] | begin_it | Begin of range to erase.
  [in] | end_it | Behind 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## erase() [2/2]

template<size_t bit_capacity = 58>

iterator seqan3::dynamic_bitset< bit_capacity >::erase | ( | const_iterator | pos | ) |

inline constexpr noexcept

Removes specified elements from the container.

Parameters

  [in] | pos | Remove 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## flip() [1/2]

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::flip | ( |  | ) |

inline constexpr noexcept

Flips all bits (binary NOT).

Returns
  *this

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.flip();
seqan3::debug_stream << t1 << '\n'; // 0111'0011
}
seqan3::dynamic_bitset::flip
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition dynamic_bitset.hpp:964

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## flip() [2/2]

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::flip | ( | size_t const | i | ) |

inline constexpr

Flips the i'th bit (binary NOT).

Parameters

  [in] | i | Index of the bit to flip.

Exceptions

  std::out_of_range | if you access an element behind the last.

Returns
  *this

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.flip(0);
t1.flip(3);
seqan3::debug_stream << t1 << '\n'; // 1000'0101
}

### Exception

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

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## front() [1/2]

template<size_t bit_capacity = 58>

const_reference seqan3::dynamic_bitset< bit_capacity >::front | ( |  | ) | const

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## front() [2/2]

template<size_t bit_capacity = 58>

reference seqan3::dynamic_bitset< bit_capacity >::front | ( |  | ) |

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## 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>>

iterator seqan3::dynamic_bitset< bit_capacity >::insert | ( | const_iterator | pos,
|  | begin_it_type | begin_it,
|  | end_it_type | end_it )

inline constexpr noexcept

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

Template Parameters

  begin_it_type | Must model std::forward_iterator and the value_type must be constructible from the reference type of begin_it_type.
  end_it_type | Must model std::sentinel_for.

Parameters

  [in] | pos | Iterator before which the content will be inserted. pos may be the end() iterator.
  [in] | begin_it | Begin of range to construct/assign from.
  [in] | end_it | End 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## insert() [2/4]

template<size_t bit_capacity = 58>

iterator seqan3::dynamic_bitset< bit_capacity >::insert | ( | const_iterator | pos,
|  | size_type const | count,
|  | value_type const | value )

inline constexpr noexcept

Inserts count copies of value before position in the container.

Parameters

  [in] | pos | Iterator before which the content will be inserted. pos may be the end() iterator.
  [in] | count | Number of copies.
  [in] | value | Element 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## insert() [3/4]

template<size_t bit_capacity = 58>

iterator seqan3::dynamic_bitset< bit_capacity >::insert | ( | const_iterator | pos,
|  | std::initializer_list< value_type > const & | ilist )

inline constexpr noexcept

Inserts elements from initializer list before pos in the container.

Parameters

  [in] | pos | Iterator before which the content will be inserted. pos may be the end() iterator.
  [in] | ilist | Initializer 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## insert() [4/4]

template<size_t bit_capacity = 58>

iterator seqan3::dynamic_bitset< bit_capacity >::insert | ( | const_iterator | pos,
|  | value_type const | value )

inline constexpr noexcept

Inserts value before pos in the container.

Parameters

  [in] | pos | Iterator before which the content will be inserted. pos may be the end() iterator.
  [in] | value | Element 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## max_size()

template<size_t bit_capacity = 58>

size_type seqan3::dynamic_bitset< bit_capacity >::max_size | ( |  | ) | const

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## none()

template<size_t bit_capacity = 58>

bool seqan3::dynamic_bitset< bit_capacity >::none | ( |  | ) | const

inline constexpr noexcept

Checks if no bit is set.

Returns
  true if no bit is set, false otherwise.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator&=()

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::operator&= | ( | dynamic_bitset< bit_capacity > const & | rhs | ) |

inline constexpr noexcept

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

Parameters

  [in] | rhs | dynamic_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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
seqan3::dynamic_bitset const t2{0b1011'1000};
t1 &= t2;
seqan3::debug_stream << t1 << '\n'; // 1000'1000
}

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator<<()

template<size_t bit_capacity = 58>

dynamic_bitset seqan3::dynamic_bitset< bit_capacity >::operator<< | ( | size_t const | count | ) | const

inline constexpr noexcept

Performs binary shift left.

Parameters

  [in] | count | Amount to shift to the left.

Returns
  Copy of *this with bits shifted count to the left.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset const t1{"10001100"};
seqan3::dynamic_bitset t2 = t1 << 3;
seqan3::debug_stream << t2 << '\n'; // 0110'0000
}

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator<<=()

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::operator<<= | ( | size_t const | count | ) |

inline constexpr noexcept

Performs binary shift left on the current object.

Parameters

  [in] | count | Amount to shift to the left.

Returns
  *this

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1 <<= 3;
seqan3::debug_stream << t1 << '\n'; // 0110'0000
}

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator=() [1/2]

template<size_t bit_capacity = 58>
template<size_t N>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::operator= | ( | char const (&) | lit[N] | ) |

inline constexpr

Assign from literal.

Parameters

  [in] | lit | The literal to assign the string from. May only contain `'0'` and `'1'`.

Exceptions

  std::invalid_argument | if 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'`.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator=() [2/2]

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::operator= | ( | std::initializer_list< value_type > const | ilist | ) |

inline constexpr noexcept

Assign from std::initializer_list.

Parameters

  [in] | ilist | A std::initializer_list of value_type.

### Complexity

Linear in the size of ilist.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator>>()

template<size_t bit_capacity = 58>

dynamic_bitset seqan3::dynamic_bitset< bit_capacity >::operator>> | ( | size_t const | count | ) | const

inline constexpr noexcept

Performs binary shift right.

Parameters

  [in] | count | Amount to shift to the right.

Returns
  Copy of *this with bits shifted count to the right.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset const t1{"10001100"};
seqan3::dynamic_bitset t2 = t1 >> 3;
seqan3::debug_stream << t2 << '\n'; // 0001'0001
}

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator>>=()

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::operator>>= | ( | size_t const | count | ) |

inline constexpr noexcept

Performs binary shift right on the current object.

Parameters

  [in] | count | Amount to shift to the right.

Returns
  *this

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1 >>= 3;
seqan3::debug_stream << t1 << '\n'; // 0001'0001
}

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator[]() [1/2]

template<size_t bit_capacity = 58>

const_reference seqan3::dynamic_bitset< bit_capacity >::operator[] | ( | size_t const | i | ) | const

inline constexpr noexcept

Returns the i-th element.

Parameters

  [in] | i | The 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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::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)
seqan3::debug_stream << t1[i]; // 1111'0001'1101
seqan3::debug_stream << '\n';
}
seqan3::dynamic_bitset::size
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition dynamic_bitset.hpp:1232

### Complexity

Constant.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator[]() [2/2]

template<size_t bit_capacity = 58>

reference seqan3::dynamic_bitset< bit_capacity >::operator[] | ( | size_t const | i | ) |

inline constexpr noexcept

Returns the i-th element.

Parameters

  [in] | i | The 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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::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)
seqan3::debug_stream << t1[i]; // 1111'0001'1101
seqan3::debug_stream << '\n';
}

### Complexity

Constant.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator^=()

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::operator^= | ( | dynamic_bitset< bit_capacity > const & | rhs | ) |

inline constexpr noexcept

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

Parameters

  [in] | rhs | dynamic_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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
seqan3::dynamic_bitset const t2{0b1011'1000};
t1 ^= t2;
seqan3::debug_stream << t1 << '\n'; // 0011'0100
}

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator|=()

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::operator|= | ( | dynamic_bitset< bit_capacity > const & | rhs | ) |

inline constexpr noexcept

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

Parameters

  [in] | rhs | dynamic_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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
seqan3::dynamic_bitset const t2{0b1011'1000};
t1 |= t2;
seqan3::debug_stream << t1 << '\n'; // 1011'1100
}

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator~()

template<size_t bit_capacity = 58>

dynamic_bitset seqan3::dynamic_bitset< bit_capacity >::operator~ | ( |  | ) | const

inline constexpr noexcept

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

Returns
  Copy of *this with all bits flipped.

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset const t1{"10001100"};
seqan3::dynamic_bitset t2 = ~t1;
seqan3::debug_stream << t2 << '\n'; // 0111'0011
}

### Exception

No-throw guarantee.

### Thread-safety

Thread safe.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## pop_back()

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::pop_back | ( |  | ) |

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## push_back()

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::push_back | ( | value_type const | value | ) |

inline constexpr noexcept

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

Parameters

  [in] | value | The value to append.

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

### Complexity

Constant.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## raw_data() [1/2]

template<size_t bit_capacity = 58>

bitfield const * seqan3::dynamic_bitset< bit_capacity >::raw_data | ( |  | ) | const

inline constexpr noexcept

Direct access to the underlying bit field.

This entity is not part of the SeqAn API. Do not rely on it in your applications. The exact representation of the data is implementation defined.

## raw_data() [2/2]

template<size_t bit_capacity = 58>

bitfield * seqan3::dynamic_bitset< bit_capacity >::raw_data | ( |  | ) |

inline constexpr noexcept

Direct access to the underlying bit field.

This entity is not part of the SeqAn API. Do not rely on it in your applications. The exact representation of the data is implementation defined.

## reserve()

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::reserve | ( | size_t |  | ) | const

inline constexpr noexcept

Since the capacity is fixed on compile time, this is a no-op.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## reset() [1/2]

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::reset | ( |  | ) |

inline constexpr noexcept

Sets all bits to 0.

Returns
  *this

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

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.reset();
seqan3::debug_stream << t1 << '\n'; // 0000'0000
}
seqan3::dynamic_bitset::reset
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition dynamic_bitset.hpp:912

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## reset() [2/2]

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::reset | ( | size_t const | i | ) |

inline constexpr

Sets the i'th bit to false.

Parameters

  [in] | i | Index of the bit to reset.

Exceptions

  std::out_of_range | if you access an element behind the last.

Returns
  *this

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.reset(2);
t1.reset(3);
seqan3::debug_stream << t1 << '\n'; // 1000'0000
}

### Exception

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

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## resize()

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::resize | ( | size_type const | count,
|  | value_type const | value = false )

inline constexpr noexcept

Resizes the container to contain count elements.

Parameters

  [in] | count | The new size.
  [in] | value | Append 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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"1100"};
t1.resize(8); // Enlarge to 8.
seqan3::debug_stream << t1 << '\n'; // 0000'1100
t1.resize(5); // Shrink to 5, last three bits (5, 6, 7) are set to false.
seqan3::debug_stream << t1 << '\n'; // 0110'0
t1.resize(10, true); // Enlarge to 10 and set new bits to true.
seqan3::debug_stream << t1 << '\n'; // 1111'1011'00
}
seqan3::dynamic_bitset::resize
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition dynamic_bitset.hpp:1588

### Complexity

Constant.

### Exceptions

No-throw guarantee.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## set() [1/2]

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::set | ( |  | ) |

inline constexpr noexcept

Sets all bits to 1.

Returns
  *this

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.set();
seqan3::debug_stream << t1 << '\n'; // 1111'1111
}
seqan3::dynamic_bitset::set
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition dynamic_bitset.hpp:856

### Exception

No-throw guarantee.

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## set() [2/2]

template<size_t bit_capacity = 58>

dynamic_bitset & seqan3::dynamic_bitset< bit_capacity >::set | ( | size_t const | i,
|  | bool const | value = true )

inline constexpr

Sets the i'th bit to value.

Parameters

  [in] | i | Index of the bit to set.
  [in] | value | Value to set. Default true.

Exceptions

  std::out_of_range | if you access an element behind the last.

Returns
  *this

### Example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.set(0);
t1.set(2, false);
seqan3::debug_stream << t1 << '\n'; // 1000'1001
}

### Exception

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

### Complexity

Constant.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## shrink_to_fit()

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::shrink_to_fit | ( |  | ) | const

inline constexpr noexcept

Since the capacity is fixed on compile time, this is a no-op.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## size()

template<size_t bit_capacity = 58>

size_type seqan3::dynamic_bitset< bit_capacity >::size | ( |  | ) | const

inline constexpr noexcept

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## swap()

template<size_t bit_capacity = 58>

void seqan3::dynamic_bitset< bit_capacity >::swap | ( | dynamic_bitset< bit_capacity > & | rhs | ) |

inline constexpr noexcept

Swap contents with another instance.

Parameters

  [in] | rhs | The 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## test()

template<size_t bit_capacity = 58>

const_reference seqan3::dynamic_bitset< bit_capacity >::test | ( | size_t const | i | ) | const

inline constexpr

Returns the i-th element.

Parameters

  [in] | i | Index of the element to retrieve.

Exceptions

  std::out_of_range | If 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().

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## to_string()

template<size_t bit_capacity = 58>
template<typename char_t = char>

std::string seqan3::dynamic_bitset< bit_capacity >::to_string | ( | char_t | zero = char_t{'0'},
|  | char_t | one = char_t{'1'} ) const

inline

Converts the dynamic_bitset to a std::string.

Template Parameters

  char_t | Char type; must model seqan3::builtin_character.

Parameters

  [in] | zero | builtin_character of type char_t representing false. Default `'0'`.
  [in] | one | builtin_character of type char_t representing true. Default `'1'`.

Exceptions

  std::bad_alloc | from the the std::string constructor.

Returns
  A std::string representing the dynamic_bitset.

Attention
  This is the only function of this class that is not constexpr because std::string is not constexpr.

### Complexity

Linear in size().

### Exceptions

Throws std::bad_alloc from the std::string constructor.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## to_ullong()

template<size_t bit_capacity = 58>

unsigned long long seqan3::dynamic_bitset< bit_capacity >::to_ullong | ( |  | ) | const

inline constexpr

Converts the dynamic_bitset to an unsigned long long integer.

Exceptions

  std::overflow_error | if 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## to_ulong()

template<size_t bit_capacity = 58>

unsigned long seqan3::dynamic_bitset< bit_capacity >::to_ulong | ( |  | ) | const

inline constexpr

Converts the dynamic_bitset to an unsigned long integer.

Exceptions

  std::overflow_error | if 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## Friends And Related Symbol Documentation

## operator!=

template<size_t bit_capacity = 58>
template<size_t cap>

bool operator!= | ( | dynamic_bitset< bit_capacity > const & | lhs,
|  | dynamic_bitset< cap > const & | rhs )

friend

Performs element-wise comparison.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator&

template<size_t bit_capacity = 58>
template<size_t cap>
requires (cap <= bit_capacity)

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator<

template<size_t bit_capacity = 58>
template<size_t cap>

bool operator< | ( | dynamic_bitset< bit_capacity > const & | lhs,
|  | dynamic_bitset< cap > const & | rhs )

friend

Performs element-wise comparison.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator<<

template<size_t bit_capacity = 58>

std::ostream & operator<< | ( | std::ostream & | os,
|  | dynamic_bitset< bit_capacity > const & | arg )

friend

Formatted output for the seqan3::dynamic_bitset.

Parameters

  [in,out] | os | The std::basic_ostream to write to.
  [in] | arg | The seqan3::dynamic_bitset to read from.

Returns
  os.

Internally calls `os << arg.to_string()`.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator<=

template<size_t bit_capacity = 58>
template<size_t cap>

bool operator<= | ( | dynamic_bitset< bit_capacity > const & | lhs,
|  | dynamic_bitset< cap > const & | rhs )

friend

Performs element-wise comparison.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator==

template<size_t bit_capacity = 58>
template<size_t cap>

bool operator== | ( | dynamic_bitset< bit_capacity > const & | lhs,
|  | dynamic_bitset< cap > const & | rhs )

friend

Performs element-wise comparison.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator>

template<size_t bit_capacity = 58>
template<size_t cap>

bool operator> | ( | dynamic_bitset< bit_capacity > const & | lhs,
|  | dynamic_bitset< cap > const & | rhs )

friend

Performs element-wise comparison.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator>=

template<size_t bit_capacity = 58>
template<size_t cap>

bool operator>= | ( | dynamic_bitset< bit_capacity > const & | lhs,
|  | dynamic_bitset< cap > const & | rhs )

friend

Performs element-wise comparison.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator>>

template<size_t bit_capacity = 58>

std::istream & operator>> | ( | std::istream & | is,
|  | dynamic_bitset< bit_capacity > & | arg )

friend

Formatted input for the seqan3::dynamic_bitset.

Parameters

  [in,out] | is | The std::basic_istream to read from.
  [out] | arg | The seqan3::dynamic_bitset to write to.

Returns
  is.

Reads at most seqan3::dynamic_bitset::max_size() characters from the stream. If a stream error occurred or no characters could be extracted the std::ios_base::failbit is set. This may throw an exception.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator^

template<size_t bit_capacity = 58>
template<size_t cap>
requires (cap <= bit_capacity)

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## operator|

template<size_t bit_capacity = 58>
template<size_t cap>
requires (cap <= bit_capacity)

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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

## swap

template<size_t bit_capacity = 58>

void swap | ( | dynamic_bitset< bit_capacity > & | lhs,
|  | dynamic_bitset< bit_capacity > & | rhs )

friend

Swap contents with another instance.

Parameters

  [in] | lhs | The first instance.
  [in] | rhs | The 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.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

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

- dynamic_bitset.hpp

Hide me