aboutsummaryrefslogtreecommitdiffstats
path: root/src/3rdparty/masm/stubs/wtf/Optional.h
blob: 3f7f99eb55c9eba2c64ea1f296f96cda2bc81b07 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#pragma once

#include <QtCore/qglobal.h>
#include <QtQml/private/qtqmlglobal_p.h>

#include <memory>
#if __cplusplus > 201402L && __has_include(<optional>)
#include <optional>
#else

namespace std {

struct nullopt_t {};

constexpr nullopt_t nullopt {};

template<typename T>
class optional {
public:
    optional() = default;
    optional(nullopt_t) {}
    optional(const T &v) : _value(v), _hasValue(true) {}
    ~optional() = default;

    optional &operator =(nullopt_t) {
        _value = T();
        _hasValue = false;
        return *this;
    }

    T operator->() { return _value; }
    T operator*() { return _value; }

    operator bool() const { return _hasValue; }
    bool has_value() const { return _hasValue; }

    T value() const { return _value; }

private:
    T _value = T();
    bool _hasValue = false;
};

}

#endif