Loading...
Searching...
No Matches
tstr.hpp
Go to the documentation of this file.
1
2#pragma once
3
6
7namespace by {
8
14 template <typename T, typename TACTIC = strTactic> class tstr: public tweak<T, TACTIC> {
16 BY(ME(tstr, _super_), INIT_META(me))
17
18 public:
19 // tstr:
20 tstr();
21
26 tstr(const type& subtype);
27 tstr(const T& it);
28 tstr(const T* it);
29 tstr(const tmedium<T>& it);
30 tstr(const binder& rhs);
31 tstr(const me& rhs);
32
33 me& operator=(const me& rhs) = default;
34 };
35
36 // extension for OR macro:
37 template <typename T, typename F> tmedium<T> operator|(tstr<T>& t, F&& f) {
38 f(t);
39 // this returns null-reference but take it easy.
40 // it'll never be used.
41 return t.get();
42 }
43
44 template <typename T, typename F> tmedium<T> operator|(const tstr<T>& t, F&& f) {
45 f(t);
46 // this returns null-reference but take it easy.
47 // it'll never be used.
48 return t.get();
49 }
50
51 template <typename T, typename F> tstr<T> operator|(tstr<T>&& t, F&& f) {
52 f(t);
53 // this returns null-reference but take it easy.
54 // it'll never be used.
55 return t;
56 }
57
58 template <typename F> tstr<instance> operator|(binder&& t, F&& f) {
59 f(t);
60 // this returns null-reference but take it easy.
61 // it'll never be used.
62 return t.get();
63 }
64
65 // extension for typeTrait:
66 template <typename T> struct typeTrait<tstr<T>> {
67 typedef tstr<T> Org;
68 typedef tstr<T>& Ref;
69 typedef tstr<T>* Ptr;
70
71 static tstr<T> ret() { return tstr<T>{}; } // return default value
72
73 static nbool isNul(const tstr<T>& it) { return !it.isBind(); }
74
75 static constexpr nbool is_ptr = false;
76 static constexpr nbool is_ref = false;
77 static constexpr nbool is_like_ptr = true;
78 };
79
80 template <typename T> struct typeTrait<tstr<T>*> {
81 typedef tstr<T> Org;
82 typedef tstr<T>& Ref;
83 typedef tstr<T>* Ptr;
84
85 static tstr<T>* ret() { return nullptr; }
86
87 static nbool isNul(const tstr<T>* it) { return !it || !it->isBind(); }
88
89 static constexpr nbool is_ptr = true;
90 static constexpr nbool is_ref = false;
91 static constexpr nbool is_like_ptr = is_ptr;
92 };
93
94 template <typename T> struct typeTrait<tstr<T>&> {
95 typedef tstr<T> Org;
96 typedef tstr<T>& Ref;
97 typedef tstr<T>* Ptr;
98
99 static nbool isNul(const tstr<T>& it) { return !it.isBind(); }
100
101 static tstr<T>& ret() {
102 static tstr<T> dummy;
103 return dummy;
104 }
105
106 static constexpr nbool is_ptr = false;
107 static constexpr nbool is_ref = true;
108 static constexpr nbool is_like_ptr = true;
109 };
110
111 // extension for TO macro:
112 template <typename T, typename F>
113 auto operator->*(tstr<T>& t, F&& f) -> decltype(typeTrait<decltype(f(*t))>::ret()) {
114 return t ? f(*t) : typeTrait<decltype(f(*t))>::ret();
115 }
116
117 template <typename T, typename F>
118 auto operator->*(const tstr<T>& t, F&& f) -> decltype(typeTrait<decltype(f(*t))>::ret()) {
119 return t ? f(*t) : typeTrait<decltype(f(*t))>::ret();
120 }
121
122 template <typename T, typename F>
123 auto operator->*(tstr<T>&& t, F&& f) -> decltype(typeTrait<decltype(f(*t))>::ret()) {
124 return t ? f(*t) : typeTrait<decltype(f(*t))>::ret();
125 }
126} // namespace by
Generalized binding class for managing instance lifecycles.
Definition binder.hpp:108
Strong reference smart pointer with strict type checking.
Definition tstr.hpp:14
Weak reference smart pointer with type-safe access.
Definition tweak.hpp:16
Core class for runtime type information in byeol language.
Definition type.hpp:100
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34