<xstd/bits/ext/boost/dynamic_bitset.hpp>¶
namespace xstd {
// exported, and valid with boost::dynamic_bitset<Block, AllocatorOrContainer> at either end
template<class To, class From>
requires see below
constexpr auto bit_convert(From&& from) noexcept(see below) -> remove_cv_t<To>;
}
<xstd/bits.hpp> and <xstd/bits/ext/boost.hpp> do not include this header, so the dependency on
Boost.DynamicBitset is opted into by name. Including
it is what makes the conversions valid; it declares no name of its own and exports bit_convert.
xstd::bit_convert with boost::dynamic_bitset¶
Makes boost::dynamic_bitset<Block, AllocatorOrContainer> either end of bit_convert.
As a source¶
A dynamic_bitset is a sequence of its size(), of run-time width, read through boost::to_block_range, each of
its blocks landing on its own positions at any target block width:
- into a run-time target, as from any run-time sequence: a sequence target takes its size, a set target whole blocks
of its own, and an inplace target too small throws
bad_alloc; - into a fixed target, by value: zero-extended, and
overflow_errorfor a position at or past the target's width.
As a target¶
bit_convert<boost::dynamic_bitset<Block, AllocatorOrContainer>>(from) takes a source of ours that is an owner, a
whole view or a fixed width, a bitset and a block among them. The result is the source's width, as a sequence
target takes it, written through boost::from_block_range in blocks of its own width.
A window is no source for a dynamic_bitset, and one dynamic_bitset converts into no other.
Exceptions¶
Into a dynamic_bitset, any exception its allocation throws. Neither direction is noexcept.
Remarks¶
- Boost hands its blocks out nowhere, so both directions copy: an rvalue
dynamic_bitsetsource keeps its bits, and nothing is adopted even where its container is an owner's own. - Since Boost 1.90 the container parameter converts like any other, a
small_vectorof blocks included, and both directions are usable in a constant expression. - As with
bitset, itsto_string()writes position 0 last.
Notes¶
A dynamic_bitset<uint8_t> of 13 with positions {0, 5, 12} converts to a bit_vector of 13 with them, and back
to an equal dynamic_bitset<uint8_t>. bit_convert<boost::dynamic_bitset<>>(bit_set{3, 64, 129}) has the set's
whole blocks as its size, and bit_convert<boost::dynamic_bitset<uint8_t>>(bit_array<20>()) 20.
See also¶
| Entity | Relation |
|---|---|
bit_convert |
the conversion this header extends |
boost::dynamic_bitset |
the Boost type it converts to and from |