49template <
size_t bit_capacity = 58>
67 bitfield data{0u, 0u};
70 class reference_proxy_type
76 constexpr reference_proxy_type() noexcept = default;
77 constexpr reference_proxy_type(reference_proxy_type const &) noexcept = default;
78 constexpr reference_proxy_type(reference_proxy_type &&) noexcept = default;
81 constexpr reference_proxy_type & operator=(reference_proxy_type const rhs) noexcept
83 rhs ? set() : reset();
88 constexpr reference_proxy_type & operator=(
bool const value)
noexcept
90 value ? set() : reset();
94 ~reference_proxy_type() noexcept = default;
99 constexpr reference_proxy_type(bitfield & internal_,
size_t const pos) noexcept :
105 constexpr operator bool() const noexcept
107 return static_cast<bool>(
internal.bits & mask);
111 constexpr bool operator~() const noexcept
113 return !
static_cast<bool>(
internal.bits & mask);
117 constexpr reference_proxy_type & operator|=(
bool const value)
126 constexpr reference_proxy_type & operator&=(
bool const value)
135 constexpr reference_proxy_type & operator^=(
bool const value)
137 operator bool() && value ? reset() : set();
148 constexpr void set() noexcept
154 constexpr void reset() noexcept
161 static_assert(bit_capacity <= 58,
"The capacity of the dynamic_bitset exceeds the limit of 58.");
188 using iterator = detail::random_access_iterator<dynamic_bitset>;
266 template <std::forward_iterator begin_it_type,
typename end_it_type>
267 requires std::sentinel_for<end_it_type, begin_it_type>
268 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
291 template <std::ranges::input_range other_range_t>
292 requires (!std::same_as<std::remove_cvref_t<other_range_t>,
dynamic_bitset>)
365 static_assert(N <=
bit_capacity + 1,
"Length of string literal exceeds capacity of dynamic_bitset.");
391 static_assert(N <=
bit_capacity + 1,
"Length of string literal exceeds capacity of dynamic_bitset.");
418 static_assert(N <=
bit_capacity + 1,
"Length of string literal exceeds capacity of dynamic_bitset.");
422 for (
size_t i = 0;
i != N - 1; ++
i)
428 else if (
lit[
i] ==
'1')
435 throw std::invalid_argument{
"The string to construct a dynamic_bitset from may only contain 0 and 1."};
503 template <std::ranges::input_range other_range_t>
504 requires std::constructible_from<value_type, std::ranges::range_reference_t<other_range_t>>
529 template <std::forward_iterator begin_it_type,
typename end_it_type>
530 requires std::sentinel_for<end_it_type, begin_it_type>
531 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
626 data.bits &=
rhs.data.bits;
656 data.bits |=
rhs.data.bits;
686 data.bits ^=
rhs.data.bits;
745 data.bits &= (1ULL <<
size()) - 1ULL;
856 data.bits |= (1ULL <<
size()) - 1ULL;
964 data.bits = ~data.bits;
965 data.bits &= (1ULL <<
size()) - 1ULL;
1017 return count() != 0;
1027 return count() == 0;
1112 return data.bits & 1ULL <<
i;
1166 return (*
this)[
size() - 1];
1173 return (*
this)[
size() - 1];
1346 return insert(pos, 1, value);
1399 template <std::forward_iterator begin_it_type,
typename end_it_type>
1400 requires std::sentinel_for<end_it_type, begin_it_type>
1401 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
1405 auto const length = std::ranges::distance(begin_it, end_it);
1414 (*
this)[
i] = (*this)[
i - length];
1417 for (
auto i =
pos_as_num; begin_it != end_it; ++
i, ++begin_it)
1418 (*
this)[
i] = *begin_it;
1472 if (begin_it >= end_it)
1473 return begin() + std::ranges::distance(
cbegin(), end_it);
1475 auto const length = std::ranges::distance(begin_it, end_it);
1478 while (end_it !=
cend())
1479 *(
out_it++) = *(end_it++);
1482 return begin() + std::ranges::distance(
cbegin(), begin_it);
1509 return erase(pos, pos + 1);
1533 (*this)[
size() - 1] = value;
1594 data.bits &= (1ULL <<
size()) - 1ULL;
1614 bitfield
tmp = std::move(data);
1615 data = std::move(
rhs.data);
1616 rhs.data = std::move(
tmp);
1622 data = std::move(
rhs.data);
1661 template <
size_t cap>
1681 template <
size_t cap>
1701 template <
size_t cap>
1719 template <
size_t cap>
1722 return lhs.data.size ==
rhs.raw_data()->size &&
lhs.data.bits ==
rhs.raw_data()->bits;
1729 template <
size_t cap>
1739 template <
size_t cap>
1742 return lhs.data.bits <
rhs.raw_data()->bits;
1749 template <
size_t cap>
1752 return lhs.data.bits >
rhs.raw_data()->bits;
1759 template <
size_t cap>
1769 template <
size_t cap>
1801 template <
typename char_t =
char>
1806 for (
bool const bit :
std::views::
reverse(*this))
1833 throw std::overflow_error{
"seqan3::dynamic_bitset cannot be represented as unsigned long."};
1836 return static_cast<unsigned long>(data.bits);
1860 throw std::overflow_error{
"seqan3::dynamic_bitset cannot be represented as unsigned long long."};
1863 return static_cast<unsigned long long>(data.bits);
1883 os <<
arg.to_string();
1908 (is.
width() > 0) ? std::min<std::streamsize>(is.
width(),
arg.max_size()) :
arg.max_size();
1915 c == is.
widen(
'0') ?
tmp.push_back(
false) :
tmp.push_back(
true);
1918 arg.assign(std::views::reverse(
tmp));
1920 if (
arg.size() == 0)
1921 is.
setstate(std::ios_base::failbit);
1940 template <cereal_archive archive_t>
1943 uint64_t
size = data.size;
1946 uint64_t bits = data.bits;
1957template <
size_t bit_capacity>
1966 template <
typename stream_t,
typename arg_t>
1985template <
size_t cap>
1997 return static_cast<size_t>(arg.to_ullong());
Adaptions of concepts from the Cereal library.
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
A constexpr bitset implementation with dynamic size at compile time.
Definition dynamic_bitset.hpp:51
constexpr dynamic_bitset operator<<(size_t const count) const noexcept
Performs binary shift left.
Definition dynamic_bitset.hpp:826
friend class dynamic_bitset
Befriend other template instantiations of dynamic_bitset.
Definition dynamic_bitset.hpp:55
constexpr iterator insert(const_iterator pos, value_type const value) noexcept
Inserts value before pos in the container.
Definition dynamic_bitset.hpp:1344
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition dynamic_bitset.hpp:1230
constexpr iterator insert(const_iterator pos, std::initializer_list< value_type > const &ilist) noexcept
Inserts elements from initializer list before pos in the container.
Definition dynamic_bitset.hpp:1442
constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
Performs binary shift left on the current object.
Definition dynamic_bitset.hpp:740
constexpr bool any() const noexcept
Checks if any bit is set.
Definition dynamic_bitset.hpp:1015
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition dynamic_bitset.hpp:1586
friend constexpr bool operator<(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1740
constexpr const_reference test(size_t const i) const
Returns the i-th element.
Definition dynamic_bitset.hpp:1074
constexpr reference back() noexcept
Returns the last element.
Definition dynamic_bitset.hpp:1163
friend std::istream & operator>>(std::istream &is, dynamic_bitset &arg)
Formatted input for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1900
constexpr void clear() noexcept
Removes all elements from the container.
Definition dynamic_bitset.hpp:1319
constexpr size_type count() const noexcept
Returns the number of set bits.
Definition dynamic_bitset.hpp:1034
constexpr reference front() noexcept
Returns the first element.
Definition dynamic_bitset.hpp:1133
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition dynamic_bitset.hpp:1210
constexpr size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold and resolves to bit_capacity.
Definition dynamic_bitset.hpp:1255
constexpr void shrink_to_fit() const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition dynamic_bitset.hpp:1293
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.
Definition dynamic_bitset.hpp:623
constexpr bool all() const noexcept
Checks if all bit are set.
Definition dynamic_bitset.hpp:1005
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition dynamic_bitset.hpp:962
friend constexpr bool operator==(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1720
reference_proxy_type reference
A proxy type that enables assignment.
Definition dynamic_bitset.hpp:176
constexpr void assign(char const (&lit)[N])
Assign from literal.
Definition dynamic_bitset.hpp:416
constexpr const_iterator begin() const noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:558
constexpr unsigned long to_ulong() const
Converts the dynamic_bitset to an unsigned long integer.
Definition dynamic_bitset.hpp:1828
constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
Assign from pair of iterators.
Definition dynamic_bitset.hpp:532
constexpr void swap(dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition dynamic_bitset.hpp:1612
constexpr dynamic_bitset(other_range_t &&range) noexcept
Construct from a different range.
Definition dynamic_bitset.hpp:293
constexpr void swap(dynamic_bitset &&rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition dynamic_bitset.hpp:1620
constexpr dynamic_bitset(char const (&lit)[N])
Construction from literal.
Definition dynamic_bitset.hpp:363
constexpr reference at(size_t const i)
Returns the i-th element.
Definition dynamic_bitset.hpp:1056
constexpr dynamic_bitset & operator=(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition dynamic_bitset.hpp:333
constexpr dynamic_bitset & reset(size_t const i)
Sets the i'th bit to false.
Definition dynamic_bitset.hpp:937
constexpr iterator erase(const_iterator pos) noexcept
Removes specified elements from the container.
Definition dynamic_bitset.hpp:1507
constexpr size_type capacity() const noexcept
Returns the number of elements that the container is able to hold and resolves to bit_capacity.
Definition dynamic_bitset.hpp:1275
constexpr bitfield const * raw_data() const noexcept
Direct access to the underlying bit field.
Definition dynamic_bitset.hpp:1186
constexpr void push_back(value_type const value) noexcept
Appends the given element value to the end of the container.
Definition dynamic_bitset.hpp:1529
constexpr const_iterator cbegin() const noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:564
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.
Definition dynamic_bitset.hpp:1402
constexpr dynamic_bitset operator>>(size_t const count) const noexcept
Performs binary shift right.
Definition dynamic_bitset.hpp:797
constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept
Construct from two iterators.
Definition dynamic_bitset.hpp:269
constexpr const_reference operator[](size_t const i) const noexcept
Returns the i-th element.
Definition dynamic_bitset.hpp:1109
constexpr unsigned long long to_ullong() const
Converts the dynamic_bitset to an unsigned long long integer.
Definition dynamic_bitset.hpp:1855
constexpr const_reference back() const noexcept
Returns the last element.
Definition dynamic_bitset.hpp:1170
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition dynamic_bitset.hpp:854
constexpr bitfield * raw_data() noexcept
Direct access to the underlying bit field.
Definition dynamic_bitset.hpp:1180
friend std::ostream & operator<<(std::ostream &os, dynamic_bitset const &arg)
Formatted output for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1881
constexpr iterator end() noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:579
constexpr void pop_back() noexcept
Removes the last element of the container.
Definition dynamic_bitset.hpp:1554
constexpr const_reference at(size_t const i) const
Returns the i-th element.
Definition dynamic_bitset.hpp:1065
friend constexpr bool operator>=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1770
constexpr iterator begin() noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:552
constexpr void assign(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition dynamic_bitset.hpp:458
constexpr dynamic_bitset & set(size_t const i, bool const value=true)
Sets the i'th bit to value.
Definition dynamic_bitset.hpp:882
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition dynamic_bitset.hpp:910
constexpr const_iterator cend() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:591
constexpr bool none() const noexcept
Checks if no bit is set.
Definition dynamic_bitset.hpp:1025
constexpr dynamic_bitset operator~() const noexcept
Returns a temporary copy of *this with all bits flipped (binary NOT).
Definition dynamic_bitset.hpp:713
constexpr const_iterator end() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:585
constexpr dynamic_bitset & operator=(char const (&lit)[N])
Assign from literal.
Definition dynamic_bitset.hpp:389
friend constexpr void swap(dynamic_bitset &lhs, dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition dynamic_bitset.hpp:1643
constexpr void assign(size_type const count, value_type const value) noexcept
Assign with count times value.
Definition dynamic_bitset.hpp:479
ptrdiff_t difference_type
A std::ptrdiff_t.
Definition dynamic_bitset.hpp:200
constexpr dynamic_bitset() noexcept=default
Defaulted.
constexpr const_reference front() const noexcept
Returns the first element.
Definition dynamic_bitset.hpp:1140
constexpr void assign(other_range_t &&range) noexcept
Assign from a different range.
Definition dynamic_bitset.hpp:505
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.
Definition dynamic_bitset.hpp:1802
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.
Definition dynamic_bitset.hpp:683
constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
Removes specified elements from the container.
Definition dynamic_bitset.hpp:1470
constexpr void reserve(size_t) const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition dynamic_bitset.hpp:1284
constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
Performs binary shift right on the current object.
Definition dynamic_bitset.hpp:769
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.
Definition dynamic_bitset.hpp:653
friend constexpr bool operator<=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1760
detail::random_access_iterator< dynamic_bitset > iterator
The iterator type of this container (a random access iterator).
Definition dynamic_bitset.hpp:188
constexpr dynamic_bitset(size_type const n, value_type const value) noexcept
Construct with n times value.
Definition dynamic_bitset.hpp:313
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.
Definition dynamic_bitset.hpp:1369
detail::random_access_iterator< dynamic_bitset const > const_iterator
The const_iterator type of this container (a random access iterator).
Definition dynamic_bitset.hpp:194
constexpr reference operator[](size_t const i) noexcept
Returns the i-th element.
Definition dynamic_bitset.hpp:1102
friend constexpr bool operator>(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1750
friend constexpr bool operator!=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1730
constexpr dynamic_bitset & flip(size_t const i)
Flips the i'th bit (binary NOT).
Definition dynamic_bitset.hpp:990
Provides seqan3::debug_stream and related types.
seqan::stl::ranges::to to
Converts a range to a container. <dl class="no-api">This entity is not part of the SeqAn API....
Definition to.hpp:23
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition interleave.hpp:375
Provides metaprogramming utilities for integer types.
Provides seqan3::views::interleave.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
Provides seqan3::views::repeat_n.
constexpr void operator()(stream_t &stream, arg_t &&arg) const
Prints the dynamic bitset.
Definition dynamic_bitset.hpp:1967
Definition default_printer.hpp:34
size_t operator()(seqan3::dynamic_bitset< cap > const arg) const noexcept
Compute the hash for a seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1995
Provides seqan3::ranges::to.