C/C++ API Reference
Loading...
Searching...
No Matches
pw::BitSet< kBits > Class Template Reference

Overview

template<size_t kBits>
class pw::BitSet< kBits >

A constexpr-friendly fixed-size sequence of bits, similar to std::bitset.

This container allows for compile-time manipulation of a fixed number of bits. It supports common bitwise operations and is optimized for size by using the smallest possible underlying integer type.

Template Parameters
kBitsThe number of bits in the set (must be <= 64).

Public Types

using value_type = std::conditional_t< kBits<=8, uint8_t, std::conditional_t< kBits<=16, uint16_t, std::conditional_t< kBits<=32, uint32_t, uint64_t > > >
 

Public Member Functions

constexpr BitSet (const BitSet &)=default
 
constexpr BitSetoperator= (const BitSet &)=default
 
template<size_t kOtherBits, typename = std::enable_if_t<kBits >= kOtherBits>
constexpr BitSet (const BitSet< kOtherBits > &other)
 
template<size_t kOtherBits, typename = std::enable_if_t<kBits >= kOtherBits>
constexpr BitSetoperator= (const BitSet &other)
 
constexpr bool operator== (const BitSet &other) const
 
constexpr bool operator!= (const BitSet &other) const
 
template<size_t kBit>
constexpr bool test () const
 
constexpr bool all () const
 
constexpr bool any () const
 
constexpr bool none () const
 
constexpr size_t count () const
 
constexpr size_t size () const
 
constexpr BitSetset ()
 
template<size_t... kBitsToSet>
constexpr BitSetset ()
 
constexpr BitSetreset ()
 
template<size_t... kBitsToReset>
constexpr BitSetreset ()
 
constexpr BitSetflip ()
 
template<size_t... kBitsToFlip>
constexpr BitSetflip ()
 
constexpr BitSetoperator&= (const BitSet &other)
 
constexpr BitSetoperator|= (const BitSet &other)
 
constexpr BitSetoperator^= (const BitSet &other)
 
constexpr BitSetoperator<<= (size_t pos)
 
constexpr BitSetoperator>>= (size_t pos)
 
constexpr BitSet operator~ () const
 
constexpr value_type to_integer () const
 Returns the bit set as an integer.
 

Static Public Member Functions

template<unsigned long long kValue>
static constexpr BitSet Of ()
 
template<typename... Args, typename = std::enable_if_t<(std::is_same_v<Args, bool> && ...)>>
static constexpr BitSet LittleEndian (Args... bits_least_to_most_significant)
 

Friends

constexpr BitSet operator& (const BitSet &lhs, const BitSet &rhs)
 
constexpr BitSet operator| (const BitSet &lhs, const BitSet &rhs)
 
constexpr BitSet operator^ (const BitSet &lhs, const BitSet &rhs)
 
constexpr BitSet operator<< (const BitSet &bs, size_t pos)
 
constexpr BitSet operator>> (const BitSet &bs, size_t pos)
 

Member Typedef Documentation

◆ value_type

template<size_t kBits>
using pw::BitSet< kBits >::value_type = std::conditional_t< kBits <= 8, uint8_t, std::conditional_t<kBits <= 16, uint16_t, std::conditional_t<kBits <= 32, uint32_t, uint64_t> >>

The underlying type used to store the bits. Uses the smallest integer type capable of representing the bits.

Member Function Documentation

◆ LittleEndian()

template<size_t kBits>
template<typename... Args, typename = std::enable_if_t<(std::is_same_v<Args, bool> && ...)>>
static constexpr BitSet pw::BitSet< kBits >::LittleEndian ( Args...  bits_least_to_most_significant)
inlinestaticconstexpr

Initialize a bitset from true/false or 1/0, with the LEAST significant bit first.

◆ Of()

template<size_t kBits>
template<unsigned long long kValue>
static constexpr BitSet pw::BitSet< kBits >::Of ( )
inlinestaticconstexpr

Initializes a bitset from an integer (e.g. 0b1010). The integer must fit within size() bits.


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