CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
BitArray Class Referencefinal

Array of bits More...

#include <cc/BitArray>

Classes

class  Access
 Provide access to a single bit in a BitArray. More...
 

Public Types

using Item = bool
 Item type.
 

Public Member Functions

 BitArray ()
 Create an empty bit array.
 
 BitArray (long n, bool on=false)
 Create a new bit array of n bits preset to on.
 
long count () const
 Number of bits.
 
bool has (long i) const
 Check if i is a valid index.
 
 operator bool () const
 Check if this bit array is non-empty.
 
long operator+ () const
 Number of bits.
 
bool at (long i) const
 Read the bit at index i.
 
Access at (long i)
 Access the bit at index i
 
bool operator[] (long i) const
 Read the bit at index i.
 
Access operator[] (long i)
 Access the bit at index i
 
bool operator() (long i, bool fallback=false) const
 Get value at index if 0 <= index && index < count(), otherwise return fallback.
 
void fill (bool on)
 Set all bits to on
 
BitArray copy () const
 Create a deep copy of this array.
 

Standard Iterators

using value_type = Item
 Item value type.
 
using size_type = long
 Type of the container capacity.
 
using iterator = ArrayIterator<BitArray, 1>
 Value iterator.
 
using const_iterator = ArrayIterator<const BitArray, 1>
 Readonly value iterator.
 
using reverse_iterator = ArrayIterator<BitArray, -1>
 Reverse value iterator.
 
using const_reverse_iterator = ArrayIterator<const BitArray, -1>
 Readonly reverse value iterator.
 
iterator begin ()
 Return iterator pointing to the first item (if any)
 
iterator end ()
 Return iterator pointing behind the last item
 
const_iterator begin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator cbegin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator end () const
 Return readonly iterator pointing behind the last item
 
const_iterator cend () const
 Return readonly iterator pointing behind the last item
 
reverse_iterator rbegin ()
 Return reverse iterator pointing to the last item (if any)
 
reverse_iterator rend ()
 Return reverse iterator pointing before the first item
 
const_reverse_iterator rbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator crbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator rend () const
 Return reverse iterator pointing before the first item
 
const_reverse_iterator crend () const
 Return reverse iterator pointing before the first item
 

Comparism Operators

bool operator== (const BitArray &other) const
 Equal to operator.
 
bool operator!= (const BitArray &other) const
 Not equal to operator.
 

Detailed Description

Array of bits

Member Typedef Documentation

◆ Item

using Item = bool

Item type.

◆ value_type

using value_type = Item

Item value type.

◆ size_type

using size_type = long

Type of the container capacity.

◆ iterator

Value iterator.

◆ const_iterator

Readonly value iterator.

◆ reverse_iterator

Reverse value iterator.

◆ const_reverse_iterator

Readonly reverse value iterator.

Constructor & Destructor Documentation

◆ BitArray() [1/2]

BitArray ( )

Create an empty bit array.

◆ BitArray() [2/2]

BitArray ( long n,
bool on = false )
explicit

Create a new bit array of n bits preset to on.

Member Function Documentation

◆ count()

long count ( ) const

Number of bits.

◆ has()

bool has ( long i) const

Check if i is a valid index.

◆ operator bool()

operator bool ( ) const
explicit

Check if this bit array is non-empty.

◆ operator+()

long operator+ ( ) const

Number of bits.

◆ at() [1/2]

bool at ( long i) const

Read the bit at index i.

◆ at() [2/2]

Access at ( long i)

Access the bit at index i

◆ operator[]() [1/2]

bool operator[] ( long i) const

Read the bit at index i.

◆ operator[]() [2/2]

Access operator[] ( long i)

Access the bit at index i

◆ operator()()

bool operator() ( long i,
bool fallback = false ) const

Get value at index if 0 <= index && index < count(), otherwise return fallback.

◆ fill()

void fill ( bool on)

Set all bits to on

◆ copy()

BitArray copy ( ) const

Create a deep copy of this array.

◆ begin() [1/2]

BitArray::iterator begin ( )

Return iterator pointing to the first item (if any)

◆ end() [1/2]

Return iterator pointing behind the last item

◆ begin() [2/2]

BitArray::const_iterator begin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ cbegin()

BitArray::const_iterator cbegin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ end() [2/2]

BitArray::const_iterator end ( ) const

Return readonly iterator pointing behind the last item

◆ cend()

BitArray::const_iterator cend ( ) const

Return readonly iterator pointing behind the last item

◆ rbegin() [1/2]

Return reverse iterator pointing to the last item (if any)

◆ rend() [1/2]

Return reverse iterator pointing before the first item

◆ rbegin() [2/2]

Return readonly reverse iterator pointing to the last item (if any)

◆ crbegin()

Return readonly reverse iterator pointing to the last item (if any)

◆ rend() [2/2]

Return reverse iterator pointing before the first item

◆ crend()

Return reverse iterator pointing before the first item

◆ operator==()

bool operator== ( const BitArray & other) const

Equal to operator.

◆ operator!=()

bool operator!= ( const BitArray & other) const

Not equal to operator.