dynamic_bitset
Public Member Functions | Friends | List of all members
dynamic_bitset< N > Class Template Reference

A dynamic bitset implementation that can be resized at runtime. More...

#include <dynamic_bitset.hpp>

Public Member Functions

 dynamic_bitset ()
 Default constructor that initializes the bitset with the default size. More...
 
 dynamic_bitset (int value)
 Constructor that initializes the bitset with a given integer value. More...
 
 dynamic_bitset (std::vector< bool > binaries)
 Constructor that initializes the bitset with a vector of bools. More...
 
 dynamic_bitset (std::initializer_list< bool > binaries)
 Constructor that initializes the bitset with an initializer list of bools. More...
 
 dynamic_bitset (const std::string &binary_string)
 Constructor that initializes the bitset with a string of binary digits. More...
 
 dynamic_bitset (const char *binary)
 Constructor that initializes the bitset with a C-style string of binary digits. More...
 
 ~dynamic_bitset ()
 Destructor for dynamic_bitset. More...
 
 dynamic_bitset (const dynamic_bitset &)=delete
 Delete the copy constructor for dynamic_bitset. More...
 
dynamic_bitsetoperator= (const dynamic_bitset &)=delete
 Delete the copy assignment operator for dynamic_bitset. More...
 
 dynamic_bitset (dynamic_bitset &&other)
 Move constructor for dynamic_bitset. More...
 
dynamic_bitsetoperator= (dynamic_bitset &&other)
 Move assignment operator for dynamic_bitset. More...
 
dynamic_bitsetoperator= (const std::vector< bool > &binaries)
 Assignment operator to assign a std::vector<bool> to dynamic_bitset. More...
 
dynamic_bitsetreverse ()
 Reverse the bits in dynamic_bitset. More...
 
const std::vector< bool > & get () const
 Get the underlying std::vector<bool> object. More...
 
bool operator[] (std::size_t index) const
 Get the value of a bit at a given index. More...
 
bool all () const
 Check if all bits in dynamic_bitset are true. More...
 
bool any () const
 Check if any bit in dynamic_bitset is true. More...
 
bool none () const
 Check if none of the bits in dynamic_bitset are true. More...
 
std::vector< bool >::reference operator[] (std::size_t index)
 Return reference bit on the given index. More...
 
constexpr std::size_t size () const
 Return size of the bitset. More...
 
dynamic_bitsetset (bool value)
 Set all value of the bitset. More...
 
dynamic_bitsetreset ()
 Set all value to 0. More...
 
std::string to_string () const
 convert bitset to string bitset More...
 
 operator std::string () const
 string casting operator, return bitset to string More...
 
std::size_t to_ulong () const
 bitset to std::size_t More...
 
 operator std::size_t () const
 casting operator of std::size_t More...
 
 operator unsigned long const ()
 casting operator of unsigned long More...
 
 operator unsigned long long const ()
 casting operator of unsigned long long More...
 
dynamic_bitset operator& (const dynamic_bitset &other) const
 and operator between two dynamic_bitset More...
 
dynamic_bitsetoperator&= (const dynamic_bitset &other)
 and operator between two dynamic_bitset and change orginal set More...
 
dynamic_bitset operator| (const dynamic_bitset &other) const
 or operator between two dynamic_bitset More...
 
dynamic_bitsetoperator|= (const dynamic_bitset &other)
 or operator between two dynamic_bitset and change orginal set More...
 
dynamic_bitset operator^ (const dynamic_bitset &other) const
 xor operator between two dynamic_bitset More...
 
dynamic_bitsetoperator^= (const dynamic_bitset &other)
 xor operator between two dynamic_bitset and change orginal set More...
 
dynamic_bitsetoperator<<= (std::size_t shift_amount)
 Left Shift operator. More...
 
dynamic_bitsetoperator>>= (std::size_t shift_amount)
 Right Shift operator. More...
 
std::vector< bool >::iterator begin ()
 begin iterator More...
 
std::vector< bool >::iterator end ()
 begin iterator More...
 

Friends

std::ostream & operator<< (std::ostream &out, const dynamic_bitset &set)
 ostream operator to print dynamic_bitset More...
 
std::istream & operator>> (std::istream &input, dynamic_bitset &set)
 istream operator to input of dynamic_bitset More...
 

Detailed Description

template<std::size_t N = 0>
class dynamic_bitset< N >

A dynamic bitset implementation that can be resized at runtime.

The dynamic_bitset class provides a simple implementation of a bitset that can be resized at runtime. It supports all the basic bit operations, such as AND, OR, NOT, and XOR, as well as various other functions such as reverse, to_string, and to_ulong.

Template Parameters
NThe default size of the bitset. If no size is specified, the bitset will be empty and ready for dynamic usage.

Definition at line 24 of file dynamic_bitset.hpp.

Constructor & Destructor Documentation

◆ dynamic_bitset() [1/8]

template<std::size_t N = 0>
dynamic_bitset< N >::dynamic_bitset ( )
inline

Default constructor that initializes the bitset with the default size.

Definition at line 30 of file dynamic_bitset.hpp.

Here is the caller graph for this function:

◆ dynamic_bitset() [2/8]

template<std::size_t N = 0>
dynamic_bitset< N >::dynamic_bitset ( int  value)
inline

Constructor that initializes the bitset with a given integer value.

Parameters
valueThe integer value to initialize the bitset with.

Definition at line 37 of file dynamic_bitset.hpp.

◆ dynamic_bitset() [3/8]

template<std::size_t N = 0>
dynamic_bitset< N >::dynamic_bitset ( std::vector< bool >  binaries)
inline

Constructor that initializes the bitset with a vector of bools.

Parameters
binariesThe vector of bools to initialize the bitset with.

Definition at line 49 of file dynamic_bitset.hpp.

◆ dynamic_bitset() [4/8]

template<std::size_t N = 0>
dynamic_bitset< N >::dynamic_bitset ( std::initializer_list< bool >  binaries)
inline

Constructor that initializes the bitset with an initializer list of bools.

Parameters
binariesThe initializer list of bools to initialize the bitset with.

Definition at line 62 of file dynamic_bitset.hpp.

◆ dynamic_bitset() [5/8]

template<std::size_t N = 0>
dynamic_bitset< N >::dynamic_bitset ( const std::string &  binary_string)
inline

Constructor that initializes the bitset with a string of binary digits.

Parameters
binary_stringThe string of binary digits to initialize the bitset with.

Definition at line 75 of file dynamic_bitset.hpp.

◆ dynamic_bitset() [6/8]

template<std::size_t N = 0>
dynamic_bitset< N >::dynamic_bitset ( const char *  binary)
inline

Constructor that initializes the bitset with a C-style string of binary digits.

Parameters
binaryThe C-style string of binary digits to initialize the bitset with.

Definition at line 86 of file dynamic_bitset.hpp.

◆ ~dynamic_bitset()

template<std::size_t N = 0>
dynamic_bitset< N >::~dynamic_bitset ( )
inline

Destructor for dynamic_bitset.

Definition at line 100 of file dynamic_bitset.hpp.

◆ dynamic_bitset() [7/8]

template<std::size_t N = 0>
dynamic_bitset< N >::dynamic_bitset ( const dynamic_bitset< N > &  )
delete

Delete the copy constructor for dynamic_bitset.

◆ dynamic_bitset() [8/8]

template<std::size_t N = 0>
dynamic_bitset< N >::dynamic_bitset ( dynamic_bitset< N > &&  other)
inline

Move constructor for dynamic_bitset.

Parameters
otherThe dynamic_bitset object to move from.

Definition at line 116 of file dynamic_bitset.hpp.

Member Function Documentation

◆ operator=() [1/3]

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::operator= ( const dynamic_bitset< N > &  )
delete

Delete the copy assignment operator for dynamic_bitset.

◆ operator=() [2/3]

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::operator= ( dynamic_bitset< N > &&  other)
inline

Move assignment operator for dynamic_bitset.

Parameters
otherThe dynamic_bitset object to move from.
Returns
A reference to the dynamic_bitset object after the move.

Definition at line 123 of file dynamic_bitset.hpp.

◆ operator=() [3/3]

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::operator= ( const std::vector< bool > &  binaries)
inline

Assignment operator to assign a std::vector<bool> to dynamic_bitset.

Parameters
binariesThe std::vector<bool> to assign.
Returns
A reference to the dynamic_bitset object after the assignment.

Definition at line 136 of file dynamic_bitset.hpp.

◆ reverse()

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::reverse ( )
inline

Reverse the bits in dynamic_bitset.

Returns
A reference to the dynamic_bitset object after the reverse operation.

Definition at line 148 of file dynamic_bitset.hpp.

◆ get()

template<std::size_t N = 0>
const std::vector<bool>& dynamic_bitset< N >::get ( ) const
inline

Get the underlying std::vector<bool> object.

Returns
A const reference to the std::vector<bool> object.

Definition at line 158 of file dynamic_bitset.hpp.

◆ operator[]() [1/2]

template<std::size_t N = 0>
bool dynamic_bitset< N >::operator[] ( std::size_t  index) const
inline

Get the value of a bit at a given index.

Parameters
indexThe index of the bit.
Returns
The value of the bit at the given index.

Definition at line 165 of file dynamic_bitset.hpp.

◆ all()

template<std::size_t N = 0>
bool dynamic_bitset< N >::all ( ) const
inline

Check if all bits in dynamic_bitset are true.

Returns
True if all bits are true, false otherwise.

Definition at line 171 of file dynamic_bitset.hpp.

◆ any()

template<std::size_t N = 0>
bool dynamic_bitset< N >::any ( ) const
inline

Check if any bit in dynamic_bitset is true.

Returns
True if any bit is true, false otherwise.

Definition at line 180 of file dynamic_bitset.hpp.

◆ none()

template<std::size_t N = 0>
bool dynamic_bitset< N >::none ( ) const
inline

Check if none of the bits in dynamic_bitset are true.

Returns
True if none of the bits are true, false otherwise.

Definition at line 189 of file dynamic_bitset.hpp.

◆ operator[]() [2/2]

template<std::size_t N = 0>
std::vector<bool>::reference dynamic_bitset< N >::operator[] ( std::size_t  index)
inline

Return reference bit on the given index.

Returns
Reference bit on the given index

Definition at line 198 of file dynamic_bitset.hpp.

◆ size()

template<std::size_t N = 0>
constexpr std::size_t dynamic_bitset< N >::size ( ) const
inlineconstexpr

Return size of the bitset.

Returns
sizse of bitset, if empty return 0

Definition at line 206 of file dynamic_bitset.hpp.

Here is the caller graph for this function:

◆ set()

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::set ( bool  value)
inline

Set all value of the bitset.

Returns
Return object itself

Definition at line 212 of file dynamic_bitset.hpp.

Here is the caller graph for this function:

◆ reset()

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::reset ( )
inline

Set all value to 0.

Returns
Return object itself

Definition at line 221 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ to_string()

template<std::size_t N = 0>
std::string dynamic_bitset< N >::to_string ( ) const
inline

convert bitset to string bitset

Returns
Return string

Definition at line 227 of file dynamic_bitset.hpp.

Here is the caller graph for this function:

◆ operator std::string()

template<std::size_t N = 0>
dynamic_bitset< N >::operator std::string ( ) const
inline

string casting operator, return bitset to string

Returns
Return string

Definition at line 239 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ to_ulong()

template<std::size_t N = 0>
std::size_t dynamic_bitset< N >::to_ulong ( ) const
inline

bitset to std::size_t

Returns
return std::size_t, max possible of value

Definition at line 246 of file dynamic_bitset.hpp.

Here is the caller graph for this function:

◆ operator std::size_t()

template<std::size_t N = 0>
dynamic_bitset< N >::operator std::size_t ( ) const
inline

casting operator of std::size_t

Returns
return std::size_t, max possible of value

Definition at line 261 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator unsigned long const()

template<std::size_t N = 0>
dynamic_bitset< N >::operator unsigned long const ( )
inline

casting operator of unsigned long

Returns
return std::size_t, max possible value

Definition at line 267 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator unsigned long long const()

template<std::size_t N = 0>
dynamic_bitset< N >::operator unsigned long long const ( )
inline

casting operator of unsigned long long

Returns
return std::size_t, max possible value

Definition at line 276 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator&()

template<std::size_t N = 0>
dynamic_bitset dynamic_bitset< N >::operator& ( const dynamic_bitset< N > &  other) const
inline

and operator between two dynamic_bitset

Returns
return new dynamic_bitset

Definition at line 285 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator&=()

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::operator&= ( const dynamic_bitset< N > &  other)
inline

and operator between two dynamic_bitset and change orginal set

Returns
dynamic_bitset itself

Definition at line 298 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator|()

template<std::size_t N = 0>
dynamic_bitset dynamic_bitset< N >::operator| ( const dynamic_bitset< N > &  other) const
inline

or operator between two dynamic_bitset

Returns
return new dynamic_bitset

Definition at line 309 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator|=()

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::operator|= ( const dynamic_bitset< N > &  other)
inline

or operator between two dynamic_bitset and change orginal set

Returns
dynamic_bitset itself

Definition at line 322 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator^()

template<std::size_t N = 0>
dynamic_bitset dynamic_bitset< N >::operator^ ( const dynamic_bitset< N > &  other) const
inline

xor operator between two dynamic_bitset

Returns
return new dynamic_bitset

Definition at line 334 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator^=()

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::operator^= ( const dynamic_bitset< N > &  other)
inline

xor operator between two dynamic_bitset and change orginal set

Returns
dynamic_bitset itself

Definition at line 346 of file dynamic_bitset.hpp.

Here is the call graph for this function:

◆ operator<<=()

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::operator<<= ( std::size_t  shift_amount)
inline

Left Shift operator.

Template Parameters
shift_amount,amountof the shift that will used for left shifting
Returns
dynamic_bitset itself

Definition at line 359 of file dynamic_bitset.hpp.

◆ operator>>=()

template<std::size_t N = 0>
dynamic_bitset& dynamic_bitset< N >::operator>>= ( std::size_t  shift_amount)
inline

Right Shift operator.

Template Parameters
shift_amount,amountof the shift that will used for right shifting
Returns
dynamic_bitset itself

Definition at line 378 of file dynamic_bitset.hpp.

◆ begin()

template<std::size_t N = 0>
std::vector<bool>::iterator dynamic_bitset< N >::begin ( )
inline

begin iterator

Returns
dynamic_bitset begin itreator

Definition at line 396 of file dynamic_bitset.hpp.

◆ end()

template<std::size_t N = 0>
std::vector<bool>::iterator dynamic_bitset< N >::end ( )
inline

begin iterator

Returns
dynamic_bitset begin itreator

Definition at line 402 of file dynamic_bitset.hpp.

Friends And Related Function Documentation

◆ operator<<

template<std::size_t N = 0>
std::ostream& operator<< ( std::ostream &  out,
const dynamic_bitset< N > &  set 
)
friend

ostream operator to print dynamic_bitset

Returns
ostream

Definition at line 409 of file dynamic_bitset.hpp.

◆ operator>>

template<std::size_t N = 0>
std::istream& operator>> ( std::istream &  input,
dynamic_bitset< N > &  set 
)
friend

istream operator to input of dynamic_bitset

Returns
istream

Definition at line 422 of file dynamic_bitset.hpp.


The documentation for this class was generated from the following file: