Code style tweak in optional.hh
This commit is contained in:
parent
4c2ed2062a
commit
9672e9219d
|
@ -12,12 +12,12 @@ template<typename T>
|
||||||
struct Optional
|
struct Optional
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr Optional() : m_valid(false) {}
|
constexpr Optional() : m_valid{false} {}
|
||||||
Optional(const T& other) : m_valid(true) { new (&m_value) T(other); }
|
Optional(const T& other) : m_valid{true} { new (&m_value) T(other); }
|
||||||
Optional(T&& other) : m_valid(true) { new (&m_value) T(std::move(other)); }
|
Optional(T&& other) : m_valid{true} { new (&m_value) T(std::move(other)); }
|
||||||
|
|
||||||
Optional(const Optional& other)
|
Optional(const Optional& other)
|
||||||
: m_valid(other.m_valid)
|
: m_valid{other.m_valid}
|
||||||
{
|
{
|
||||||
if (m_valid)
|
if (m_valid)
|
||||||
new (&m_value) T(other.m_value);
|
new (&m_value) T(other.m_value);
|
||||||
|
@ -25,7 +25,7 @@ public:
|
||||||
|
|
||||||
Optional(Optional&& other)
|
Optional(Optional&& other)
|
||||||
noexcept(noexcept(new (nullptr) T(std::move(other.m_value))))
|
noexcept(noexcept(new (nullptr) T(std::move(other.m_value))))
|
||||||
: m_valid(other.m_valid)
|
: m_valid{other.m_valid}
|
||||||
{
|
{
|
||||||
if (m_valid)
|
if (m_valid)
|
||||||
new (&m_value) T(std::move(other.m_value));
|
new (&m_value) T(std::move(other.m_value));
|
||||||
|
@ -82,7 +82,7 @@ public:
|
||||||
const T* operator->() const { return const_cast<Optional&>(*this).operator->(); }
|
const T* operator->() const { return const_cast<Optional&>(*this).operator->(); }
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
T value_or(U&& fallback) const { return m_valid ? m_value : T{fallback}; }
|
T value_or(U&& fallback) const { return m_valid ? m_value : T{std::forward<U>(fallback)}; }
|
||||||
|
|
||||||
void reset() { destruct_ifn(); m_valid = false; }
|
void reset() { destruct_ifn(); m_valid = false; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user