1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#pragma once
5
6#include <QtCore/qglobal.h>
7#include <QtQml/private/qtqmlglobal_p.h>
8
9#include <memory>
10#if __cplusplus > 201402L && __has_include(<optional>)
11#include <optional>
12#else
13
14namespace std {
15
16struct nullopt_t {};
17
18constexpr nullopt_t nullopt {};
19
20template<typename T>
21class optional {
22public:
23 optional() = default;
24 optional(nullopt_t) {}
25 optional(const T &v) : _value(v), _hasValue(true) {}
26 ~optional() = default;
27
28 optional &operator =(nullopt_t) {
29 _value = T();
30 _hasValue = false;
31 return *this;
32 }
33
34 T operator->() { return _value; }
35 T operator*() { return _value; }
36
37 operator bool() const { return _hasValue; }
38 bool has_value() const { return _hasValue; }
39
40 T value() const { return _value; }
41
42private:
43 T _value = T();
44 bool _hasValue = false;
45};
46
47}
48
49#endif
50

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtdeclarative/src/3rdparty/masm/stubs/wtf/Optional.h