Commit af87826f authored by Xavier Thompson's avatar Xavier Thompson

Simplify optional.hpp

parent 1f2d6e99
......@@ -11,9 +11,6 @@ namespace typon::fdt
requires std::is_trivially_copyable_v<T>
struct optional
{
template <unsigned char I>
using state = std::integral_constant<unsigned char, I>;
unsigned char _state;
union
{
......@@ -22,14 +19,12 @@ namespace typon::fdt
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) {}
template <unsigned char I>
optional(T value, state<I> state) noexcept
: _state((state() << 1) | 1)
optional(unsigned char flags) noexcept : _state(flags << 1) {}
optional(T value, unsigned char flags) noexcept
: _state((flags << 1) | 1)
, _value(value)
{}
......@@ -46,16 +41,14 @@ namespace typon::fdt
return _state & 1;
}
template <unsigned char I>
bool match(state<I> state) noexcept
unsigned char get_flags() noexcept
{
return state() == _state >> 1;
return _state >> 1;
}
template <unsigned char I>
void set_state(state<I> state) noexcept
void set_flags(unsigned char flags) noexcept
{
_state = (state() << 1) | (_state & 1);
_state = (flags << 1) | (_state & 1);
}
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