- Download the repository and put the contents of the
include
folder to your include path. Then#include
it in your code:Also, you can use precompiled#include "path/to/bector/bector.hpp"
bector.dll
for Windows orlibbector.so
for Linux. - Create objects of the
bector
class and do what you got to do!bector bect("11001010"); std::cout << bect[4] << '\n'; // Output: 1 bect.flip(); std::cout << bect.to_string() << '\n'; // Output: 00110101
-
Constructs an empty container.
bector() = default;
-
Constructs the container with
explicit bector(size_type count);
count
zero bits. -
Constructs the container with the copy of the contents of
explicit bector(const bool *array, size_t count);
array
. -
Constructs the container with the copy of the contents of
explicit bector(const vector<bool> &vect) noexcept;
vect
. -
Constructs the container with the contents of
explicit bector(const std::string &str, char zero = '0', char one = '1');
str
interpretingone
andzero
characters as1
and0
respectively.str
must consist of onlyone
andzero
characters. -
Constructs the container with the copy of the contents of
bector(const bector &other) = default;
other
. -
Constructs the container with the contents of
bector(bector &&other) noexcept;
other
using move semantics.other
is guaranteed to beempty()
afterwards.
-
Replaces the contents with a copy of the contents of
bector &operator=(const bector &rhs) = default;
rhs
. -
Replaces the contents with those of other using move semantics.
bector &operator=(bector &&rhs) noexcept = default;
rhs
is guaranteed to beempty()
afterwards.
-
Accesses the bit at position
bool operator[](size_type pos) const;
pos
and returns the value. -
Returns the value of the first bit in the container.
bool front() const noexcept;
-
Returns the value of the last bit in the container.
bool back() const noexcept;
-
Returns a bector slice [start, end).
bector slice(size_type start, size_type end) const;
-
Returns
explicit operator bool() const noexcept;
true
if the container is not empty otherwisefalse
. -
Returns
bool operator!() const noexcept;
true
if the container is empty otherwisefalse
. -
bool all() const noexcept; // (1) bool any() const noexcept; // (2) bool none() const noexcept; // (3)
- Checks if all bits are set to
true
. - Checks if any bits are set to
true
. - Checks if none of the bits are set to
true
.
- Checks if all bits are set to
-
Returns
bool empty() const noexcept;
true
if the container has no elements. -
Returns the number of elements.
size_type size() const noexcept;
-
Returns the maximum possible number of elements.
size_type max_size() const noexcept;
-
Returns the number of elements that can be held in currently allocated storage.
size_type capacity() const noexcept;
-
Reserves storage for
void reserve(size_type new_cap);
new_cap
elements. -
Changes the number of elements stored to
void resize(size_type count);
count
. -
Reduces memory usage by freeing unused memory.
void shrink_to_fit();
-
Clears the contents.
void clear() noexcept;
-
Adds an element to the end.
void push_back(bool value = true);
-
Removes the last element.
bool pop_back();
-
bector &set() noexcept; bector &set(size_type pos, bool value = true); bector &set(size_type start, size_type end, bool value);
- Sets all bits to
true
. - Sets the bit at position
pos
to the valuevalue
. - Sets the bits [start, end) to the value
value
.
- Sets all bits to
-
bector &reset() noexcept; bector &reset(size_type pos); bector &reset(size_type start, size_type end);
- Sets all bits to
false
. - Sets the bit at position
pos
to thefalse
. - Sets the bits [start, end) to
false
.
- Sets all bits to
-
void flip() noexcept; void flip(size_type pos); void flip(size_type start, size_type end);
- Flips all bits.
- Flips the bit at position
pos
. - Flips the bits [start, end).
-
Sets the bits to the result of binary AND on corresponding pairs of bits of
bector &operator&=(const bector &rhs) noexcept;
*this
andrhs
. -
Sets the bits to the result of binary OR on corresponding pairs of bits of
bector &operator|=(const bector &rhs) noexcept;
*this
andrhs
. -
Sets the bits to the result of binary XOR on corresponding pairs of bits of
bector &operator^=(const bector &rhs) noexcept;
*this
andrhs
. -
Shifts all bits
bector &operator<<=(size_type shift) noexcept;
shift
positions left. -
Shifts all bits
bector &operator>>=(size_type shift) noexcept;
shift
positions right.
-
Converts the contents of the bector to a string. Uses
std::string to_string(char zero = '0', char one = '1') const noexcept;
zero
to represent bits with value offalse
andone
to represent bits with value oftrue
.
-
Returns a temporary copy of
bector operator~() const noexcept;
*this
with all bits flipped.
-
Returns a bector containing the result of binary AND on corresponding pairs of bits of lhs and rhs.
bector operator&(const bector &rhs) const noexcept;
-
Returns a bector containing the result of binary OR on corresponding pairs of bits of lhs and rhs.
bector operator|(const bector &rhs) const noexcept;
-
Returns a bector containing the result of binary XOR on corresponding pairs of bits of lhs and rhs.
bector operator^(const bector &rhs) const noexcept;
-
Returns a temporary copy of
bector operator<<(size_type shift) const noexcept;
*this
with all bits shiftedshift
positions left. -
Returns a temporary copy of
bector operator>>(size_type shift) const noexcept;
*this
with all bits shiftedshift
positions right.
- LHS equals RHS if both bectors are of the same size and contain the same bits on the same positions.
- LHS not equals RHS if bectors are of different sizes or contain different bits on the same potitions.
- LHS is less than RHS if LHS is smaller in size or represents a smaller integer than RHS for the same size.
- LHS is less than or equal to RHS if LHS is smaller in size or represents a smaller or the same integer as RHS for the same size.
- LHS is greater than RHS if LHS is larger in size or represents a larger integer than RHS for the same size.
- LHS is greater than or equal to RHS if LHS is larger in size or represents a larger or the same integer as RHS for the same size.
This project is licensed under the terms of the MIT license.