diff options
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)...)); } |