capydi
Loading...
Searching...
No Matches
RuntimeRef.hpp
Go to the documentation of this file.
1#ifndef RUNTIME_REF_HPP_
2#define RUNTIME_REF_HPP_
3
4#include "Reference.hpp"
5
6#include <type_traits>
7
8namespace capy::meta
9{
10
11template<typename T>
13{
14public:
15 using ReferentType = T;
16 using ReferenceType = T&;
17 using ConstReferenceType = const T&;
18
19private:
20 static constexpr bool IS_CONST = std::is_const_v<ReferentType>;
21
22public:
23 constexpr /* implicit */ RuntimeRef(ReferenceType ref)
24 : ref_ { ref }
25 {}
26
27public:
28 constexpr
29 operator ReferenceType() const noexcept requires (!IS_CONST)
30 {
31 return ref_;
32 }
33
34 constexpr
35 operator ConstReferenceType() const noexcept
36 {
37 return ref_;
38 }
39
40 constexpr
41 operator RuntimeRef<const T>() const noexcept
42 {
43 return RuntimeRef<const T> { ref_ };
44 }
45
46private:
47 ReferenceType ref_;
48};
49
50}
51
52#endif // !RUNTIME_REF_HPP_
constexpr RuntimeRef(ReferenceType ref)
Definition RuntimeRef.hpp:23
T ReferentType
Definition RuntimeRef.hpp:15
const T & ConstReferenceType
Definition RuntimeRef.hpp:17
T & ReferenceType
Definition RuntimeRef.hpp:16
Definition Rebind.hpp:7