25#ifndef TGUI_OPTIONAL_HPP
26#define TGUI_OPTIONAL_HPP
28#include <TGUI/Config.hpp>
30#if TGUI_COMPILED_WITH_CPP_VER >= 17
38#if TGUI_COMPILED_WITH_CPP_VER >= 17
40 using Optional = std::optional<T>;
46 Optional() noexcept = default;
48 Optional(const T& val) noexcept :
49 m_ptr(std::make_unique<T>(val))
53 Optional(T&& val) noexcept :
54 m_ptr(std::make_unique<T>(std::move(val)))
58 Optional(
const Optional& other) :
59 m_ptr(other.m_ptr ? std::make_unique<T>(*other.m_ptr) : nullptr)
63 Optional(Optional&& other)
noexcept =
default;
65 template<
typename... Args>
66 void emplace(Args&&... args)
68 m_ptr = std::make_unique<T>(args...);
81 const T& operator*()
const
86 T* operator->() noexcept
91 const T* operator->() const noexcept
96 Optional& operator=(std::nullptr_t)
noexcept
102 Optional& operator=(
const T& val)
noexcept
104 m_ptr = std::make_unique<T>(val);
108 Optional& operator=(T&& val)
noexcept
110 m_ptr = std::make_unique<T>(std::move(val));
114 Optional& operator=(
const Optional& other)
noexcept
116 m_ptr = other.m_ptr ? std::make_unique<T>(*other.m_ptr) : nullptr;
120 Optional& operator=(Optional&& val)
noexcept =
default;
122 bool operator==(std::nullptr_t)
const noexcept
124 return m_ptr ==
nullptr;
127 bool operator!=(std::nullptr_t)
const noexcept
129 return m_ptr !=
nullptr;
132 explicit operator bool() const noexcept
134 return m_ptr !=
nullptr;
137 const T& value()
const
148 std::unique_ptr<T> m_ptr;
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36