bit::vector — Replace Elements
Defines methods that replace some of this bit-vector’s values with those of another.
1constexpr bit::vector &replace(std::size_t i0, const bit::vector &with);
2constexpr bit::vector &replace(const bit::vector &with);- 1
-
Starting at element
i0, replace the bit-vector values with those from the bit-vectorwith. - 2
-
Starting at element 0, replace the bit-vector values with those from the bit-vector
with.
The sub-vector with we are copying from must fit inside the existing bit-vector!Set the BIT_VERIFY flag at compile time to check this condition — any violation will cause the program to abort with a helpful message.
|
Both methods return a reference to *this so can be chained with other calls.
Example
#include <bit/bit.h>
int main()
{
auto u = bit::vector<>::zeros(3);
auto v = bit::vector<>::ones(10);
std::cout << "v: " << v << '\n';
1 v.replace(7,u);
std::cout << "v: " << v << '\n';
2 v.replace(u);
std::cout << "v: " << v << '\n';
}- 1
-
Replace the final three elements of
vwith those fromu. - 2
-
Replace the first three elements of
vwith those fromu.
Output
v: [1 1 1 1 1 1 1 1 1 1]
v: [1 1 1 1 1 1 1 0 0 0]
v: [0 0 0 1 1 1 1 0 0 0]