diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-06-27 17:02:57 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-06-27 17:02:57 +0200 |
commit | 64c26487299e22a0d563fa2b9ea12aecd73ff6e4 (patch) | |
tree | 9f8b77880a97e12060b105b5725dac6a651a56f6 /modules/core | |
parent | a2f713193ecbc888a1adad7784386e6f54386d4d (diff) |
Added ref class in core and did some thoughts in thread
Diffstat (limited to 'modules/core')
-rw-r--r-- | modules/core/c++/common.hpp | 41 |
1 files changed, 41 insertions, 0 deletions
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 <typename T> using our = std::shared_ptr<T>; template <typename T> using lent = std::weak_ptr<T>; +/** + * Reference class for easier distinction + * of references and its referenced types. + */ +template <typename T> +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 <typename T, class... Args> own<T> heap(Args &&...args) { return own<T>(new T(std::forward<Args>(args)...)); } |