25#ifndef TGUI_OPTIONAL_HPP
26#define TGUI_OPTIONAL_HPP
28#include <TGUI/Config.hpp>
30#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
31 #if TGUI_COMPILED_WITH_CPP_VER >= 17
38TGUI_MODULE_EXPORT
namespace tgui
40#if TGUI_COMPILED_WITH_CPP_VER >= 17
42 using Optional = std::optional<T>;
48 Optional() noexcept = default;
50 Optional(const T& val) noexcept :
51 m_ptr(std::make_unique<T>(val))
55 Optional(T&& val) noexcept :
56 m_ptr(std::make_unique<T>(std::move(val)))
60 Optional(
const Optional& other) :
61 m_ptr(other.m_ptr ? std::make_unique<T>(*other.m_ptr) : nullptr)
65 Optional(Optional&& other)
noexcept =
default;
67 template<
typename... Args>
68 void emplace(Args&&... args)
70 m_ptr = std::make_unique<T>(args...);
83 const T& operator*()
const
88 T* operator->() noexcept
93 const T* operator->() const noexcept
98 Optional& operator=(std::nullptr_t)
noexcept
104 Optional& operator=(
const T& val)
noexcept
106 m_ptr = std::make_unique<T>(val);
110 Optional& operator=(T&& val)
noexcept
112 m_ptr = std::make_unique<T>(std::move(val));
116 Optional& operator=(
const Optional& other)
noexcept
121 m_ptr = other.m_ptr ? std::make_unique<T>(*other.m_ptr) : nullptr;
125 Optional& operator=(Optional&& val)
noexcept =
default;
127 TGUI_NODISCARD
bool operator==(std::nullptr_t)
const noexcept
129 return m_ptr ==
nullptr;
132 TGUI_NODISCARD
bool operator!=(std::nullptr_t)
const noexcept
134 return m_ptr !=
nullptr;
137 explicit operator bool() const noexcept
139 return m_ptr !=
nullptr;
142 TGUI_NODISCARD
bool has_value() const noexcept
144 return m_ptr !=
nullptr;
147 TGUI_NODISCARD
const T& value()
const
152 TGUI_NODISCARD T& value()
158 std::unique_ptr<T> m_ptr;
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38