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