diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-18 18:02:09 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-18 18:02:09 +0100 |
commit | 8d78727d6e7badca16ba7a1328643928a0039569 (patch) | |
tree | 3b0bab3c1a800f74e9f80292c9b5b7b3955ad999 /src/crepe/util/OptionalRef.h | |
parent | 121b64b1cb6cfead5814070c8b0185d3d7308095 (diff) |
move utilities from loek/audio
Diffstat (limited to 'src/crepe/util/OptionalRef.h')
-rw-r--r-- | src/crepe/util/OptionalRef.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/crepe/util/OptionalRef.h b/src/crepe/util/OptionalRef.h new file mode 100644 index 0000000..1ad3a6d --- /dev/null +++ b/src/crepe/util/OptionalRef.h @@ -0,0 +1,41 @@ +#pragma once + +namespace crepe { + +/** + * \brief Optional reference utility + * + * This class doesn't need to know the full definition of \c T to be used. + * + * \tparam T Value type + */ +template <typename T> +class OptionalRef { +public: + OptionalRef() = default; + OptionalRef(T &); + OptionalRef<T> & operator=(T &); + explicit operator bool() const noexcept; + + void set(T &) noexcept; + T & get() const; + void clear() noexcept; + + OptionalRef(const OptionalRef<T> &); + OptionalRef(OptionalRef<T> &&); + OptionalRef<T> & operator=(const OptionalRef<T> &); + OptionalRef<T> & operator=(OptionalRef<T> &&); + +private: + /** + * \brief Reference to the value of type \c T + * + * \note This raw pointer is *not* managed, and only used as a reference! + */ + T * ref = nullptr; +}; + +} + +#include "OptionalRef.hpp" + |