GF2::Vector — Extract a Sub-Vector

Extracts a sub-vector as a stand-alone, distinct copy of elements from this bit-vector.

constexpr Vector sub(std::size_t begin, std::size_t len) const;     (1)
constexpr Vector sub(int len) const;                            (2)
1 Returns a bit-vector of size len that is a copy of the elements starting at begin.
2 Returns a copy of the first len elements if len > 0 or the final abs(len) elements if len < 0.
begin has to be a valid index and abs(len) elements have to be available for copying. As usual these requirements are only checked if the GF2_DEBUG flag is set at compile time—​in which case violations will cause the program to abort with a helpful message.
Example
#include <GF2/GF2.h>
int main()
{
    auto v = GF2::Vector<>::random(12);                     (1)
    std::cout << "v:           " << v           << "\n";
    std::cout << "v.sub(0, 4): " << v.sub(0, 4) << "\n";    (2)
    std::cout << "v.sub(4):    " << v.sub(4)    << "\n";    (3)
    std::cout << "v.sub(-4):   " << v.sub(-4)   << "\n";    (4)
    std::cout << "v.sub(8, 4): " << v.sub(8, 4) << "\n";    (5)
}
1 Constructs a vector of size 12 with a random fill.
2 Extract the 4 elements starting at index 0.
3 Do the same thing using a shorthand notation.
4 Extract the final 4 elements using the shorthand notation.
5 Do the the same thing by copying 4 elements starting at index 8.
Output
v:           010110001001
v.sub(0, 4): 0101
v.sub(4):    0101
v.sub(-4):   1001
v.sub(8, 4): 1001
See Also

replace