1#ifndef BIT_NUMBER_HPP_H3ODBQR7
2#define BIT_NUMBER_HPP_H3ODBQR7
4#include <boost/operators.hpp>
16template<
typename T, std::
size_t WIDTH>
17class BitNumber :
public boost::totally_ordered<BitNumber<T, WIDTH>>
19 static_assert(std::is_integral<T>::value ==
true,
20 "only integral types are supported");
21 static_assert(
sizeof(T) * 8 > WIDTH,
22 "width has to be less than size of underlying type");
25 static constexpr T
mask = (1 << WIDTH) - 1;
26 static constexpr std::size_t
bits = WIDTH;
31 BitNumber& operator=(T value) { mValue = value &
mask;
return *
this; }
32 T raw()
const {
return mValue; }
34 bool operator<(BitNumber other)
const {
return mValue < other.mValue; }
35 bool operator==(BitNumber other)
const {
return mValue == other.mValue; }
static constexpr std::size_t bits