1#ifndef LIBSBX_MEMORY_OPTIONAL_REF_HPP_
2#define LIBSBX_MEMORY_OPTIONAL_REF_HPP_
11 using value_type = Type;
14 : _pointer{
nullptr} {}
17 : _pointer{std::addressof(value)} {}
20 : _pointer{
nullptr} {}
26 auto operator=(value_type& value)
noexcept ->
optional_ref& {
27 _pointer = std::addressof(value);
31 auto operator=(std::nullopt_t)
noexcept ->
optional_ref& {
38 [[nodiscard]]
auto has_value()
const noexcept ->
bool {
39 return _pointer !=
nullptr;
42 explicit operator bool()
const noexcept {
46 [[nodiscard]]
auto value()
const -> Type& {
48 throw std::bad_optional_access{};
54 [[nodiscard]]
auto operator*()
const noexcept -> Type& {
58 [[nodiscard]]
auto operator->()
const noexcept -> Type* {
63 [[nodiscard]]
auto value_or(U&& fallback)
const noexcept -> Type& {
64 return _pointer ? *_pointer :
static_cast<Type&
>(fallback);
67 auto reset()
noexcept ->
void {
Definition: optional_ref.hpp:7