From 64c26487299e22a0d563fa2b9ea12aecd73ff6e4 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Thu, 27 Jun 2024 17:02:57 +0200 Subject: Added ref class in core and did some thoughts in thread --- modules/core/c++/common.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'modules/core') diff --git a/modules/core/c++/common.hpp b/modules/core/c++/common.hpp index d892efe..40b2c43 100644 --- a/modules/core/c++/common.hpp +++ b/modules/core/c++/common.hpp @@ -40,6 +40,47 @@ template using our = std::shared_ptr; template using lent = std::weak_ptr; +/** + * Reference class for easier distinction + * of references and its referenced types. + */ +template +class ref { +private: + /** + * Referenced type + */ + T* ref_; + + /** + * We don't want to move since the would invalidate the type. + */ + SAW_FORBID_MOVE(ref); +public: + /** + * Main constructor. + */ + ref(T& ref__): + ref_{&ref__} + {} + + SAW_DEFAULT_COPY(ref); + + /** + * Operator retrieving the itself. + */ + T& operator()(){ + return *ref_; + } + + /** + * Operator retrieving the itself. + */ + const T& operator()() const { + return *ref_; + } +}; + template own heap(Args &&...args) { return own(new T(std::forward(args)...)); } -- cgit v1.2.3