From f96c92fdd6152f287af4a57bb09d48c5e947ddbe Mon Sep 17 00:00:00 2001 From: sha512sum Date: Tue, 27 Feb 2024 18:40:25 +0000 Subject: [PATCH] Add ReferenceWrapper --- include/utempl/reference_wrapper.hpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/utempl/reference_wrapper.hpp diff --git a/include/utempl/reference_wrapper.hpp b/include/utempl/reference_wrapper.hpp new file mode 100644 index 0000000..5d3e172 --- /dev/null +++ b/include/utempl/reference_wrapper.hpp @@ -0,0 +1,41 @@ +#pragma once + +namespace utempl { +template +struct ReferenceWrapper; + +template +struct ReferenceWrapper { + inline constexpr auto operator*() -> T& { + return this->value; + }; + inline constexpr auto operator->() -> T* { + return &this->value; + }; + T&& value; +}; + +template +struct ReferenceWrapper { + inline constexpr auto operator*() -> const T& { + return this->value; + }; + inline constexpr auto operator->() -> const T* { + return &this->value; + }; + const T& value; +}; + +template +struct ReferenceWrapper { + + inline constexpr auto operator*() -> T& { + return this->value; + }; + inline constexpr auto operator->() -> T* { + return &this->value; + }; + T& value; +}; + +} // namespace utempl