Commit af87826f authored by Xavier Thompson's avatar Xavier Thompson

Simplify optional.hpp

parent 1f2d6e99
...@@ -11,9 +11,6 @@ namespace typon::fdt ...@@ -11,9 +11,6 @@ namespace typon::fdt
requires std::is_trivially_copyable_v<T> requires std::is_trivially_copyable_v<T>
struct optional struct optional
{ {
template <unsigned char I>
using state = std::integral_constant<unsigned char, I>;
unsigned char _state; unsigned char _state;
union union
{ {
...@@ -22,14 +19,12 @@ namespace typon::fdt ...@@ -22,14 +19,12 @@ namespace typon::fdt
optional() noexcept : _state(0) {} optional() noexcept : _state(0) {}
template <unsigned char I>
optional(state<I> state) noexcept : _state(state() << 1 & (~1)) {}
optional(T value) noexcept : _state(1), _value(value) {} optional(T value) noexcept : _state(1), _value(value) {}
template <unsigned char I> optional(unsigned char flags) noexcept : _state(flags << 1) {}
optional(T value, state<I> state) noexcept
: _state((state() << 1) | 1) optional(T value, unsigned char flags) noexcept
: _state((flags << 1) | 1)
, _value(value) , _value(value)
{} {}
...@@ -46,16 +41,14 @@ namespace typon::fdt ...@@ -46,16 +41,14 @@ namespace typon::fdt
return _state & 1; return _state & 1;
} }
template <unsigned char I> unsigned char get_flags() noexcept
bool match(state<I> state) noexcept
{ {
return state() == _state >> 1; return _state >> 1;
} }
template <unsigned char I> void set_flags(unsigned char flags) noexcept
void set_state(state<I> state) noexcept
{ {
_state = (state() << 1) | (_state & 1); _state = (flags << 1) | (_state & 1);
} }
T * operator->() noexcept T * operator->() noexcept
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment