bitset

Introduction

The estd::bitset is a fixed-size representation of bits. Single bit can be referred to via indices. Index access begins with the least significant bit.

A bitset is an array of bools that uses less space than an array or vector of bools because each boolean value in bitset is optimized to occupy only one bit of space rather than one separate byte.

In contrast to std::bitset this class doesn’t throw a std::out_of_range exception but calls estd_assert when the index passed to the set(), reset(), test(), and flip() functions is out of bounds.

Usage

The usage guidelines apply for bitset.

Usage guidance

The initial value for the bitset only considers the least significant bits of given size. Other bits are ignored.

If the given initial value is a positive decimal number then only the whole number part is considered.

For modifiers operator&=(), operator|=(), and operator^=() are only defined for bitsets of the same size Size.

Example

The following example shows the accessing of bitset element.

::estd::bitset<16> a(0x0000);
a[0] = true;  // a now equals 0x0001
a[4].flip();  // a now equals 0x0011
a[0] = ~a[0]; // a now equals 0x0010

The following example shows the functionality of bitset operations.

::estd::bitset<16> a; // a equals 0x0000
a.any();              // False
a.all();              // False
a.none();             // True

a.set(4); // a equals 0x0010
a.any();  // True
a.all();  // False
a.none(); // False

a.value(); // returns 2
a.flip();  // a equals 0xFFEF
a.test(0); // True

a.set();  // a equals 0xFFFF
a.any();  // True
a.all();  // True
a.none(); // False

a.reset(); // a equals 0x0000
a.size();  // returns 16