From 9d66b6cfccd15a1600c30af5e744e8b0710eeae6 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 21 Nov 2024 09:29:15 +0100 Subject: remove OptionalRef::set and OptionalRef::get --- src/crepe/util/OptionalRef.h | 22 ++++++++-------------- src/crepe/util/OptionalRef.hpp | 21 ++++++++------------- 2 files changed, 16 insertions(+), 27 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/util/OptionalRef.h b/src/crepe/util/OptionalRef.h index 57f9635..253bc07 100644 --- a/src/crepe/util/OptionalRef.h +++ b/src/crepe/util/OptionalRef.h @@ -24,19 +24,6 @@ public: * \return Reference to this (required for operator) */ OptionalRef & 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 & ref) noexcept; /** * \brief Retrieve this reference * @@ -44,7 +31,14 @@ public: * * \throws std::runtime_error if this function is called while the reference it not set */ - T & get() const; + operator T & () const; + /** + * \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 Make this reference empty */ diff --git a/src/crepe/util/OptionalRef.hpp b/src/crepe/util/OptionalRef.hpp index 71e2a39..ae7c73e 100644 --- a/src/crepe/util/OptionalRef.hpp +++ b/src/crepe/util/OptionalRef.hpp @@ -8,29 +8,19 @@ namespace crepe { template OptionalRef::OptionalRef(T & ref) { - this->set(ref); + this->ref = &ref; } template -T & OptionalRef::get() const { +OptionalRef::operator T & () const { if (this->ref == nullptr) throw std::runtime_error("OptionalRef: attempt to dereference nullptr"); return *this->ref; } -template -void OptionalRef::set(T & ref) noexcept { - this->ref = &ref; -} - -template -void OptionalRef::clear() noexcept { - this->ref = nullptr; -} - template OptionalRef & OptionalRef::operator=(T & ref) { - this->set(ref); + this->ref = &ref; return *this; } @@ -39,4 +29,9 @@ OptionalRef::operator bool() const noexcept { return this->ref != nullptr; } +template +void OptionalRef::clear() noexcept { + this->ref = nullptr; +} + } // namespace crepe -- cgit v1.2.3