aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/util
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-11 14:21:34 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-11 14:21:34 +0100
commite6a5bb579d0969245f34119ef2489f47039c523e (patch)
treee8b0b922cd28d6f83d7bf59ea1b69bbb84d0fd04 /src/crepe/util
parent7b8de90699aea153e73b5f2cee05c69b966b81be (diff)
parent78c4a8772526f40c531b5402b56932b0a41e22e8 (diff)
Merge branch 'master' into niels/remove_singleton
Diffstat (limited to 'src/crepe/util')
-rw-r--r--src/crepe/util/OptionalRef.h10
-rw-r--r--src/crepe/util/OptionalRef.hpp7
2 files changed, 16 insertions, 1 deletions
diff --git a/src/crepe/util/OptionalRef.h b/src/crepe/util/OptionalRef.h
index 3201667..1b2cb3f 100644
--- a/src/crepe/util/OptionalRef.h
+++ b/src/crepe/util/OptionalRef.h
@@ -25,7 +25,7 @@ public:
*/
OptionalRef<T> & operator=(T & ref);
/**
- * \brief Retrieve this reference
+ * \brief Retrieve this reference (cast)
*
* \returns Internal reference if it is set
*
@@ -33,6 +33,14 @@ public:
*/
operator T &() const;
/**
+ * \brief Retrieve this reference (member access)
+ *
+ * \returns Internal reference if it is set
+ *
+ * \throws std::runtime_error if this function is called while the reference it not set
+ */
+ T * operator->() const;
+ /**
* \brief Check if this reference is not empty
*
* \returns `true` if reference is set, or `false` if it is not
diff --git a/src/crepe/util/OptionalRef.hpp b/src/crepe/util/OptionalRef.hpp
index 4608c9e..5e36b3a 100644
--- a/src/crepe/util/OptionalRef.hpp
+++ b/src/crepe/util/OptionalRef.hpp
@@ -19,6 +19,13 @@ OptionalRef<T>::operator T &() const {
}
template <typename T>
+T * OptionalRef<T>::operator->() const {
+ if (this->ref == nullptr)
+ throw std::runtime_error("OptionalRef: attempt to dereference nullptr");
+ return this->ref;
+}
+
+template <typename T>
OptionalRef<T> & OptionalRef<T>::operator=(T & ref) {
this->ref = &ref;
return *this;