52 Wrapper(std::nullopt_t nullopt) : type{nullopt} {}
93 return type.has_value() && type.value() !=
nullptr;
97 [[nodiscard]]
explicit operator bool() const noexcept {
return has_value(); }
103 [[nodiscard]] T
value()
const {
return type.value_or(
nullptr); }
111 [[nodiscard]] T
expect(
const std::string &msg)
const {
143 std::optional<T> type = std::nullopt;
149 template <mxvk::WrapType T>
A nullable smart wrapper around a raw pointer.
Wrapper(Wrapper< T > &&) noexcept=default
Move constructor.
T value() const
Access the stored pointer without null checking.
T unwrap() const
Unwrap the stored pointer, panicking on null.
Wrapper()=default
Default constructor — initialises to nullopt (no value).
Wrapper(std::nullopt_t nullopt)
Construct in the empty (nullopt) state.
Wrapper< T > & operator=(const Wrapper< T > &)=default
Copy-assign from another Wrapper.
T unwrap_or(T fallback) const noexcept
Return the stored pointer or a fallback if null.
Wrapper(const Wrapper< T > &)=default
Copy constructor.
T expect(const std::string &msg) const
Unwrap with a custom panic message on null.
Wrapper< T > & operator=(std::nullopt_t nullopt)
Reset to the empty (nullopt) state.
Wrapper< T > & operator=(Wrapper< T > &&) noexcept=default
Move-assign from another Wrapper.
bool has_value() const noexcept
Check whether a non-null value is held.
Wrapper(T t)
Construct from a raw pointer.
Constrains Wrapper<T> to pointer types only.
mxvk::Wrapper< T > Wrapper
Utilities for loading and saving PNG images.