summaryrefslogtreecommitdiff
path: root/asl/meta/internal/refs.hpp
blob: b21a0a1dc594c05af4d49bc347be9ba94940c031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

#include "asl/meta/types.hpp"

namespace asl::internal {
    
template<typename T, typename = void>
inline constexpr bool is_referenceable = false;

template<typename T>
inline constexpr bool is_referenceable<T, void_t<T&>> = true;

template<typename T, bool = is_referenceable<T>>
struct as_ref_helper { using lvalue = T; using rvalue = T; };

template<typename T>
struct as_ref_helper<T, true> { using lvalue = T&; using rvalue = T&&; };

template<typename T> struct un_ref_helper { using type = T; };
template<typename T> struct un_ref_helper<T&> { using type = T; };
template<typename T> struct un_ref_helper<T&&> { using type = T; };

template<typename T>
struct is_ref_helper
{
    static inline constexpr bool lref = false;
    static inline constexpr bool rref = false;
};

template<typename T>
struct is_ref_helper<T&>
{
    static inline constexpr bool lref = true;
    static inline constexpr bool rref = false;
};

template<typename T>
struct is_ref_helper<T&&>
{
    static inline constexpr bool lref = false;
    static inline constexpr bool rref = true;
};

} // namespace asl::internal