로딩중...
검색중...
일치하는것 없음
typeTrait.hpp
이 파일의 문서화 페이지로 가기
1
2#pragma once
3
5#include <type_traits>
6
7namespace by {
8
15 template <typename T> struct typeTrait {
16 typedef T Org;
17 typedef T& Ref;
18 typedef T* Ptr;
19
20 static T ret() { return T{}; } // return default value
21
22 static bool isNul(T) { return false; }
23
24 static constexpr nbool is_ptr = false;
25 static constexpr nbool is_ref = false;
26 static constexpr nbool is_like_ptr = is_ptr;
27 };
28
29 template <typename T> struct typeTrait<T&> {
30 typedef T Org;
31 typedef T& Ref;
32 typedef T* Ptr;
33
34 static nbool isNul(const T& it) { return true; }
35
36 static T& ret() {
37 static T* dummy = nullptr;
38 return *dummy;
39 }
40
41 static constexpr nbool is_ptr = false;
42 static constexpr nbool is_ref = true;
43 static constexpr nbool is_like_ptr = is_ptr;
44 };
45
46 template <> struct typeTrait<void> {
47 static void ret() {}
48
49 static bool isNul(void) { return false; }
50
51 static constexpr nbool is_ptr = false;
52 static constexpr nbool is_ref = false;
53 static constexpr nbool is_like_ptr = is_ptr;
54 };
55
56 template <typename T> struct typeTrait<T*> {
57 typedef T Org;
58 typedef T& Ref;
59 typedef T* Ptr;
60
61 static nbool isNul(const T* it) { return it == nullptr; }
62
63 static T* ret() { return nullptr; }
64
65 static constexpr nbool is_ptr = true;
66 static constexpr nbool is_ref = false;
67 static constexpr nbool is_like_ptr = is_ptr;
68 };
69
70 template <> struct typeTrait<void*> {
71 typedef void Org;
72 typedef void* Ptr;
73
74 static nbool isNul(const void* it) { return it == nullptr; }
75
76 static void* ret() { return nullptr; }
77
78 static constexpr nbool is_ptr = true;
79 static constexpr nbool is_ref = false;
80 static constexpr nbool is_like_ptr = is_ptr;
81 };
82
83 template <typename T> auto nul(T&& it) -> decltype(typeTrait<std::remove_reference_t<std::decay_t<T>>>::isNul(it)) {
84 return typeTrait<std::remove_reference_t<std::decay_t<T>>>::isNul(std::forward<T>(it));
85 }
86} // namespace by
Weak reference smart pointer with type-safe access
Definition tweak.hpp:16
Type trait utilities for template metaprogramming
Definition typeTrait.hpp:15
to Top