sparrow 0.9.0
Loading...
Searching...
No Matches
sparrow::bitset_reference< B > Class Template Reference

A proxy reference class that provides mutable access to individual bits in a bitset. More...

#include <bitset_reference.hpp>

Public Types

using self_type = bitset_reference<B>
 This class type for convenience.
 

Public Member Functions

constexpr bitset_reference (const bitset_reference &) noexcept=default
 
constexpr bitset_reference (bitset_reference &&) noexcept=default
 
constexpr self_typeoperator= (const self_type &rhs) noexcept
 Copy assignment from another bitset_reference.
 
constexpr self_typeoperator= (self_type &&rhs) noexcept
 Move assignment from another bitset_reference.
 
constexpr self_typeoperator= (bool value) noexcept
 Assignment from a boolean value.
 
constexpr operator bool () const noexcept
 Implicit conversion to bool.
 
constexpr bool operator~ () const noexcept
 Bitwise NOT operator.
 
constexpr self_typeoperator&= (bool rhs) noexcept
 Bitwise AND assignment.
 
constexpr self_typeoperator|= (bool rhs) noexcept
 Bitwise OR assignment.
 
constexpr self_typeoperator^= (bool rhs) noexcept
 Bitwise XOR assignment.
 

Friends

class bitset_iterator< B, false >
 Mutable iterator needs access to create references.
 
template<typename RAR>
class dynamic_bitset_base
 Bitset base class needs access to create references.
 

Detailed Description

template<class B>
class sparrow::bitset_reference< B >

A proxy reference class that provides mutable access to individual bits in a bitset.

This class acts as a smart reference that allows individual bits in a bitset to be treated as if they were regular boolean references, despite being stored as packed bits within integer blocks. It provides a complete set of boolean operations and assignment operators to make bit manipulation transparent to the user.

The reference maintains a pointer to the owning bitset and the index of the bit it represents. All operations are forwarded to the appropriate bitset methods, ensuring that null count tracking and other internal state remain consistent.

Template Parameters
BThe bitset type that contains the referenced bit. Must be a type that provides test() and set() methods with appropriate signatures.
Note
This class is typically not instantiated directly by users, but rather returned by bitset indexing operations and iterators.
The reference remains valid only as long as the referenced bitset exists and the bit index remains valid (i.e., no resize operations that would invalidate the index).

Example usage:

auto ref = bits[5]; // Returns bitset_reference
ref= true; // Sets bit 5 to true
bool value = ref; // Reads bit 5
ref^= true; // Flips bit 5
A dynamic size sequence of bits with efficient storage and manipulation operations.

Definition at line 56 of file bitset_reference.hpp.

Member Typedef Documentation

◆ self_type

template<class B>
using sparrow::bitset_reference< B >::self_type = bitset_reference<B>

This class type for convenience.

Definition at line 60 of file bitset_reference.hpp.

Constructor & Destructor Documentation

◆ bitset_reference() [1/2]

template<class B>
sparrow::bitset_reference< B >::bitset_reference ( const bitset_reference< B > & )
constexprdefaultnoexcept
Here is the caller graph for this function:

◆ bitset_reference() [2/2]

template<class B>
sparrow::bitset_reference< B >::bitset_reference ( bitset_reference< B > && )
constexprdefaultnoexcept

Member Function Documentation

◆ operator bool()

template<class B>
sparrow::bitset_reference< B >::operator bool ( ) const
constexprnoexcept

Implicit conversion to bool.

Returns
The current value of the referenced bit
Postcondition
Return value represents the current state of the bit

Definition at line 227 of file bitset_reference.hpp.

Here is the call graph for this function:

◆ operator&=()

template<class B>
auto sparrow::bitset_reference< B >::operator&= ( bool rhs)
constexprnoexcept

Bitwise AND assignment.

Parameters
rhsThe boolean value to AND with the referenced bit
Returns
Reference to this object
Postcondition
The referenced bit equals (old_value AND rhs)
If rhs is false, the bit is set to false regardless of its previous value
If rhs is true, the bit retains its previous value

Definition at line 239 of file bitset_reference.hpp.

◆ operator=() [1/3]

template<class B>
auto sparrow::bitset_reference< B >::operator= ( bool value)
constexprnoexcept

Assignment from a boolean value.

Parameters
valueThe boolean value to assign to the referenced bit
Returns
Reference to this object
Postcondition
The referenced bit equals value
If the bit value changed, the bitset's null count is updated accordingly

Definition at line 220 of file bitset_reference.hpp.

◆ operator=() [2/3]

template<class B>
auto sparrow::bitset_reference< B >::operator= ( const self_type & rhs)
constexprnoexcept

Copy assignment from another bitset_reference.

Parameters
rhsThe reference to copy the value from
Returns
Reference to this object
Postcondition
The referenced bit has the same value as the bit referenced by rhs
Note
This copies the bit value, not the reference itself

Definition at line 206 of file bitset_reference.hpp.

Here is the call graph for this function:

◆ operator=() [3/3]

template<class B>
auto sparrow::bitset_reference< B >::operator= ( self_type && rhs)
constexprnoexcept

Move assignment from another bitset_reference.

Parameters
rhsThe reference to move the value from
Returns
Reference to this object
Postcondition
The referenced bit has the same value as the bit referenced by rhs
Note
This copies the bit value, not the reference itself (move semantics don't apply to bit values)

Definition at line 213 of file bitset_reference.hpp.

◆ operator^=()

template<class B>
auto sparrow::bitset_reference< B >::operator^= ( bool rhs)
constexprnoexcept

Bitwise XOR assignment.

Parameters
rhsThe boolean value to XOR with the referenced bit
Returns
Reference to this object
Postcondition
The referenced bit equals (old_value XOR rhs)
If rhs is true, the bit is flipped
If rhs is false, the bit retains its previous value

Definition at line 259 of file bitset_reference.hpp.

◆ operator|=()

template<class B>
auto sparrow::bitset_reference< B >::operator|= ( bool rhs)
constexprnoexcept

Bitwise OR assignment.

Parameters
rhsThe boolean value to OR with the referenced bit
Returns
Reference to this object
Postcondition
The referenced bit equals (old_value OR rhs)
If rhs is true, the bit is set to true regardless of its previous value
If rhs is false, the bit retains its previous value

Definition at line 249 of file bitset_reference.hpp.

◆ operator~()

template<class B>
bool sparrow::bitset_reference< B >::operator~ ( ) const
constexprnoexcept

Bitwise NOT operator.

Returns
The logical negation of the referenced bit
Postcondition
Return value is true if the bit is false, false if the bit is true
Note
This does not modify the referenced bit

Definition at line 233 of file bitset_reference.hpp.

Friends And Related Symbol Documentation

◆ bitset_iterator< B, false >

template<class B>
friend class bitset_iterator< B, false >
friend

Mutable iterator needs access to create references.

Definition at line 174 of file bitset_reference.hpp.

◆ dynamic_bitset_base

template<class B>
template<typename RAR>
friend class dynamic_bitset_base
friend

Bitset base class needs access to create references.

Definition at line 179 of file bitset_reference.hpp.


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