41template <
class Allocator>
42class VectorBoolWorkaround :
public std::vector<std::byte, Allocator>
46 using StdVectorType = std::vector<std::byte, Allocator>;
48 static bool& toBool (std::byte& element) {
return *
reinterpret_cast<bool*
> (&element); }
49 static const bool& toBool (
const std::byte& element) {
return *
reinterpret_cast<const bool*
> (&element); }
50 static bool* toBool (std::byte* ptr) {
return reinterpret_cast<bool*
> (ptr); }
51 static const bool* toBool (
const std::byte* ptr) {
return reinterpret_cast<const bool*
> (ptr); }
54 constexpr VectorBoolWorkaround (
size_t size)
55 : StdVectorType (size)
58 constexpr VectorBoolWorkaround (
size_t size,
bool value)
59 : StdVectorType (size, std::byte (value))
62 constexpr VectorBoolWorkaround (std::initializer_list<bool> il)
64 StdVectorType::reserve (il.size());
70 constexpr bool& operator[] (
size_t i) {
return toBool (StdVectorType::operator[] (i)); }
71 constexpr const bool& operator[] (
size_t i)
const {
return toBool (StdVectorType::operator[] (i)); }
72 constexpr bool& at (
size_t i) {
return toBool (StdVectorType::at (i)); }
73 constexpr const bool& at (
size_t i)
const {
return toBool (StdVectorType::at (i)); }
74 constexpr bool& front() {
return toBool (StdVectorType::front()); }
75 constexpr const bool& front()
const {
return toBool (StdVectorType::front()); }
76 constexpr bool& back() {
return toBool (StdVectorType::back()); }
77 constexpr const bool& back()
const {
return toBool (StdVectorType::back()); }
78 constexpr void push_back (
bool v) { StdVectorType::push_back (std::byte (v)); }
80 bool* data() {
return toBool (StdVectorType::data()); }
81 const bool* data()
const {
return toBool (StdVectorType::data()); }
82 bool* begin() {
return data(); }
83 const bool* begin()
const {
return data(); }
84 bool* end() {
return data() + StdVectorType::size(); }
85 const bool* end()
const {
return data() + StdVectorType::size(); }