summaryrefslogtreecommitdiff
path: root/asl/option.hpp
blob: 479383083daa7d013bae40bb82d7fb9652c42525 (plain)
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
#pragma once

#include "asl/meta.hpp"
#include "asl/maybe_uninit.hpp"

namespace asl
{

struct nullopt_t {};
static constexpr nullopt_t nullopt{};

template<is_object T>
class option
{
    maybe_uninit<T> m_payload;
    bool            m_has_value = false;

public:
    constexpr option() = default;
    constexpr option(nullopt_t) {} // NOLINT(*-explicit-conversions)

    constexpr ~option() = default;
    constexpr ~option() requires (!trivially_destructible<T>)
    {
        if (m_has_value) { m_payload.uninit_unsafe(); }
    }
    
};

} // namespace asl