18#include <QtCore/private/qglobal_p.h>
32template <
typename Value,
typename Error = QString>
38 if constexpr (
std::is_pointer_v<Value>) {
47 if constexpr (
std::is_pointer_v<Value>) {
51 m_value =
std::move(v);
58 template <
class... Args>
59 QMaybe(QUnexpect, Args &&...args) : m_error{
std::forward<Args>(args)... }
61 static_assert(
std::is_constructible_v<Error, Args &&...>,
62 "Invalid arguments for creating an error type");
68 constexpr explicit operator bool()
const noexcept {
return m_value.has_value(); }
72 Q_ASSERT(m_value.has_value());
76 constexpr const Value &
value()
const
78 Q_ASSERT(m_value.has_value());
82 constexpr Value *
operator->()
noexcept {
return std::addressof(value()); }
83 constexpr const Value *
operator->()
const noexcept {
return std::addressof(value()); }
85 constexpr Value &
operator*() &
noexcept {
return value(); }
86 constexpr const Value &
operator*()
const &
noexcept {
return value(); }
88 constexpr const Error &
error()
const {
return m_error; }
91 std::optional<Value> m_value;
QMaybe(QUnexpect, Args &&...args)
constexpr Value * operator->() noexcept
constexpr Value & value()
QMaybe & operator=(const QMaybe &other)=default
constexpr const Error & error() const
QMaybe(const QMaybe &other)=default
constexpr Value & operator*() &noexcept
constexpr const Value & value() const
constexpr const Value * operator->() const noexcept
constexpr operator bool() const noexcept
constexpr const Value & operator*() const &noexcept
static constexpr QUnexpect unexpect