SyTen
syten::Bitset< sz > Class Template Reference

Bitset class directly convertible to boolean. More...

#include <bitset.h>

+ Inheritance diagram for syten::Bitset< sz >:
+ Collaboration diagram for syten::Bitset< sz >:

Public Member Functions

 Bitset ()=default
 Default ctor. More...
 
template<typename T >
 Bitset (T const &x)
 Standard ctor: constructible from anything that can be a std::bitset constructor argument. More...
 
 operator bool () const
 True if any bit is set. More...
 
Bitset operator& (Bitset const &other) const
 Logical AND of each bit in *this and other More...
 
Bitset operator| (Bitset const &other) const
 Logical OR of each bit in *this and other More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int in_version)
 Boost serialisation support. More...
 

Static Public Attributes

static constexpr unsigned int version = 1
 Boost serialisation version. More...
 

Private Attributes

std::bitset< sz > data
 std::bitset storing the data More...
 

Detailed Description

template<std::size_t sz>
class syten::Bitset< sz >

Bitset class directly convertible to boolean.

Useful for flagged enumerations. Use as follows:

// In header file
struct Local : Bitset<2> {
static const Local A;
static const Local B;
static const Local Either;
};
// in .cpp file
const Local Local::A = Local{1};
const Local Local::B = Local{2};
const Local Local::Either = Local::A | Local::B;
void fun(Local const which) {
if (which&Local::A) {
std::cout << "Is A or Either.\n";
} else {
std::cout << "Is not A.\n";
}
}
Bitset()=default
Default ctor.
Template Parameters
szthe size of the bitset (number of bits), this many orthogonal flags are allowed

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