kblib 0.2.3
General utilities library for modern C++
kblib::bitfield< offset, size, Storage > Struct Template Reference

Implements a bitfield abstraction. May be used in a union with other bitfields. More...

#include <kblib/bits.h>

Public Member Functions

auto operator() () const noexcept -> Storage
 
auto operator() (const Storage val) noexcept -> Storage
 
 operator Storage () const noexcept
 
auto operator= (Storage val) noexcept -> Storage
 
Storage & get () noexcept
 
const Storage & get () const noexcept
 
auto operator& () -> void=delete
 

Public Attributes

Storage raw_
 

Detailed Description

template<unsigned offset, unsigned size, typename Storage>
struct kblib::bitfield< offset, size, Storage >

Implements a bitfield abstraction. May be used in a union with other bitfields.

In C++20, [[no_unique_address]] will enable a better implementation which will work in non-union structs, as long as no two bitfields name the same exact bits. ([[no_unique_address]] allows empty objects of different types to be allocated at the same location, but distinct objects of the same type must have distinct addresses, [[no_unique_address]] notwithstanding. This does not apply to unions, though.)

Template Parameters
offsetThe number of bits less significant than the bitfield.
sizeThe number of bits constituting this bitfield.
StorageThe underlying type which stores the bits.

Definition at line 437 of file bits.h.

Member Function Documentation

◆ get() [1/2]

template<unsigned offset, unsigned size, typename Storage >
const Storage & kblib::bitfield< offset, size, Storage >::get ( ) const
inlinenoexcept

Definition at line 453 of file bits.h.

◆ get() [2/2]

template<unsigned offset, unsigned size, typename Storage >
Storage & kblib::bitfield< offset, size, Storage >::get ( )
inlinenoexcept

Definition at line 452 of file bits.h.

◆ operator Storage()

template<unsigned offset, unsigned size, typename Storage >
kblib::bitfield< offset, size, Storage >::operator Storage ( ) const
inlinenoexcept

Definition at line 448 of file bits.h.

◆ operator&()

template<unsigned offset, unsigned size, typename Storage >
auto kblib::bitfield< offset, size, Storage >::operator& ( ) -> void=delete
delete

◆ operator()() [1/2]

template<unsigned offset, unsigned size, typename Storage >
auto kblib::bitfield< offset, size, Storage >::operator() ( ) const -> Storage
inlinenoexcept

Definition at line 438 of file bits.h.

◆ operator()() [2/2]

template<unsigned offset, unsigned size, typename Storage >
auto kblib::bitfield< offset, size, Storage >::operator() ( const Storage  val) -> Storage
inlinenoexcept

Definition at line 441 of file bits.h.

◆ operator=()

template<unsigned offset, unsigned size, typename Storage >
auto kblib::bitfield< offset, size, Storage >::operator= ( Storage  val) -> Storage
inlinenoexcept

Definition at line 449 of file bits.h.

Member Data Documentation

◆ raw_

template<unsigned offset, unsigned size, typename Storage >
Storage kblib::bitfield< offset, size, Storage >::raw_

Definition at line 457 of file bits.h.


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