17constexpr T&
FUN(T& t)
noexcept {
21void FUN(T&&) =
delete;
49 static_assert(!std::is_reference_v<T>,
"Type of OptionalRef should not be a reference type itself.");
70 template<class U, class = decltype(optionalref_detail::FUN<T>(std::declval<U>()),
71 std::enable_if_t<!std::is_same_v<OptionalRef, std::remove_cv_t<std::remove_reference_t<U>>>>())>
93 operator bool()
const {
94 return ptr !=
nullptr;
101 return ptr !=
nullptr;
190 ptr = std::addressof(t);
Helper class that optionally holds a reference to an object of type T.
T & value()
Accesses the contained reference (if any).
void reset(NullRefType const &)
Unsets the reference.
bool has_value() const
Yields true iff this contains a reference.
OptionalRef(NullRefType)
Creates a non-initialized reference.
T const & value_or(T const &defaultValue) const
Returns the contained reference (if any).
T & value_or(T &defaultValue)
Returns the contained reference (if any).
OptionalRef & operator=(OptionalRef const &other)=delete
Deleted assignment operator (see class description).
OptionalRef()
Creates a non-initialized reference.
T & operator*()
Accesses the contained reference (if any).
T const * operator->() const
Yields a pointer to the referenced object (if any).
OptionalRef(OptionalRef< T > const &other)=default
Creates a copy of the given OptionalRef.
void reset()
Unsets the reference.
T const & value() const
Accesses the contained reference (if any).
T * operator->()
Yields a pointer to the referenced object (if any).
OptionalRef(OptionalRef< T > &&other)=default
Move constructs this OptionalRef from another one.
T const & operator*() const
Accesses the contained reference (if any).
constexpr OptionalRef(U &&u) noexcept(noexcept(optionalref_detail::FUN< T >(std::forward< U >(u))))
Creates a reference to the provided object.
#define STORM_LOG_ASSERT(cond, message)
Helper to prevent OptionalRef's to rvalue types.
constexpr T & FUN(T &t) noexcept
OptionalRef(T &) -> OptionalRef< T >
deduction guides
constexpr NullRefType NullRef
Auxiliary struct used to identify OptionalRefs that do not contain a reference.
constexpr NullRefType(int)