-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbool.hpp
More file actions
36 lines (28 loc) · 1.11 KB
/
bool.hpp
File metadata and controls
36 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include "memory.hpp"
namespace ift630 {
// Because std::vector<bool> is a specialized version of std::vector, indexing into it returns
// std::Bit_reference rather than bool&, which causes all kinds of problems, so here is a wrapper
// type that behaves exactly like a bool
struct _bool final {
private:
bool _value{};
public:
_bool() noexcept = default;
_bool(bool value) noexcept : _value{value} {} // NOLINT
_bool(const _bool &) noexcept = default;
_bool(_bool &&) noexcept = default;
~_bool() noexcept = default;
auto operator=(const bool b) noexcept -> _bool & {
_value = b;
return *this;
}
auto operator=(const _bool &) noexcept -> _bool & = default;
auto operator=(_bool &&) noexcept -> _bool & = default;
[[nodiscard]] auto value() noexcept -> bool & { return _value; }
[[nodiscard]] auto value() const noexcept -> const bool & { return _value; }
operator bool() const noexcept { return _value; } // NOLINT
auto operator&() noexcept -> ptr<bool> { return &_value; }
auto operator&() const noexcept -> ptr<const bool> { return &_value; }
};
} // namespace ift630