Add ReferenceWrapper
This commit is contained in:
parent
a970526e4b
commit
f96c92fdd6
1 changed files with 41 additions and 0 deletions
41
include/utempl/reference_wrapper.hpp
Normal file
41
include/utempl/reference_wrapper.hpp
Normal 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
|
Loading…
Reference in a new issue