aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/util
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-19 10:29:26 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-19 10:29:26 +0100
commitc3c3476f1d82aa83d8f8dc706488475dc2cf1e55 (patch)
tree3ee5011a9b758c3b544e297977ad4ac79d830df0 /src/crepe/util
parent73598a9e7f49047d74ca439cb0f300099d8c03bf (diff)
parent5f39dc386cce357a7c71a81c523a90496f7b1e67 (diff)
merge `loek/util`
Diffstat (limited to 'src/crepe/util')
-rw-r--r--src/crepe/util/OptionalRef.h37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/crepe/util/OptionalRef.h b/src/crepe/util/OptionalRef.h
index 1ad3a6d..8417a25 100644
--- a/src/crepe/util/OptionalRef.h
+++ b/src/crepe/util/OptionalRef.h
@@ -12,18 +12,51 @@ namespace crepe {
template <typename T>
class OptionalRef {
public:
+ //! Initialize empty (nonexistant) reference
OptionalRef() = default;
- OptionalRef(T &);
- OptionalRef<T> & operator=(T &);
+ //! Initialize reference with value
+ OptionalRef(T & ref);
+ /**
+ * \brief Assign new reference
+ *
+ * \param ref Reference to assign
+ *
+ * \return Reference to this (required for operator)
+ */
+ OptionalRef<T> & operator=(T & ref);
+ /**
+ * \brief Check if this reference is not empty
+ *
+ * \returns `true` if reference is set, or `false` if it is not
+ */
explicit operator bool() const noexcept;
+ /**
+ * \brief Assign new reference
+ *
+ * \param ref Reference to assign
+ */
void set(T &) noexcept;
+ /**
+ * \brief Retrieve this reference
+ *
+ * \returns Internal reference if it is set
+ *
+ * \throws std::runtime_error if this function is called while the reference it not set
+ */
T & get() const;
+ /**
+ * \brief Make this reference empty
+ */
void clear() noexcept;
+ //! Copy constructor
OptionalRef(const OptionalRef<T> &);
+ //! Move constructor
OptionalRef(OptionalRef<T> &&);
+ //! Copy assignment
OptionalRef<T> & operator=(const OptionalRef<T> &);
+ //! Move assignment
OptionalRef<T> & operator=(OptionalRef<T> &&);
private: