Add ReferenceWrapper

This commit is contained in:
sha512sum 2024-02-27 18:40:25 +00:00
parent a970526e4b
commit f96c92fdd6

View file

@ -0,0 +1,41 @@
#pragma once
namespace utempl {
template <typename T>
struct ReferenceWrapper;
template <typename T>
struct ReferenceWrapper<T&&> {
inline constexpr auto operator*() -> T& {
return this->value;
};
inline constexpr auto operator->() -> T* {
return &this->value;
};
T&& value;
};
template <typename T>
struct ReferenceWrapper<const T&> {
inline constexpr auto operator*() -> const T& {
return this->value;
};
inline constexpr auto operator->() -> const T* {
return &this->value;
};
const T& value;
};
template <typename T>
struct ReferenceWrapper<T&> {
inline constexpr auto operator*() -> T& {
return this->value;
};
inline constexpr auto operator->() -> T* {
return &this->value;
};
T& value;
};
} // namespace utempl