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> {
17 BY_INIT_META(me)
18
19 public:
20 // tstr:
21 tstr();
22
27 tstr(const type& subtype);
28 tstr(const T& it);
29 tstr(const T* it);
30 tstr(const tmedium<T>& it);
31 tstr(const binder& rhs);
32 tstr(const me& rhs);
33
34 me& operator=(const me& rhs) = default;
35 };
36
37 // extension for OR macro:
38 template <typename T, typename F> tmedium<T> operator|(tstr<T>& t, F&& f) {
39 f(t);
40 // this returns null-reference but take it easy.
41 // it'll never be used.
42 return t.get();
43 }
44
45 template <typename T, typename F> tmedium<T> operator|(const tstr<T>& t, F&& f) {
46 f(t);
47 // this returns null-reference but take it easy.
48 // it'll never be used.
49 return t.get();
50 }
51
52 template <typename T, typename F> tstr<T> operator|(tstr<T>&& t, F&& f) {
53 f(t);
54 // this returns null-reference but take it easy.
55 // it'll never be used.
56 return t;
57 }
58
59 template <typename F> tstr<instance> operator|(binder&& t, F&& f) {
60 f(t);
61 // this returns null-reference but take it easy.
62 // it'll never be used.
63 return t.get();
64 }
65
66 // extension for typeTrait:
67 template <typename T> struct typeTrait<tstr<T>> {
68 typedef tstr<T> Org;
69 typedef tstr<T>& Ref;
70 typedef tstr<T>* Ptr;
71
72 static tstr<T> ret() { return tstr<T>{}; } // return default value
73
74 static nbool isNul(const tstr<T>& it) { return !it.isBind(); }
75
76 static constexpr nbool is_ptr = false;
77 static constexpr nbool is_ref = false;
78 static constexpr nbool is_like_ptr = true;
79 };
80
81 template <typename T> struct typeTrait<tstr<T>*> {
82 typedef tstr<T> Org;
83 typedef tstr<T>& Ref;
84 typedef tstr<T>* Ptr;
85
86 static tstr<T>* ret() { return nullptr; }
87
88 static nbool isNul(const tstr<T>* it) { return !it || !it->isBind(); }
89
90 static constexpr nbool is_ptr = true;
91 static constexpr nbool is_ref = false;
92 static constexpr nbool is_like_ptr = is_ptr;
93 };
94
95 template <typename T> struct typeTrait<tstr<T>&> {
96 typedef tstr<T> Org;
97 typedef tstr<T>& Ref;
98 typedef tstr<T>* Ptr;
99
100 static nbool isNul(const tstr<T>& it) { return !it.isBind(); }
101
102 static tstr<T>& ret() {
103 static tstr<T> dummy;
104 return dummy;
105 }
106
107 static constexpr nbool is_ptr = false;
108 static constexpr nbool is_ref = true;
109 static constexpr nbool is_like_ptr = true;
110 };
111
112 // extension for TO macro:
113 template <typename T, typename F>
114 auto operator->*(tstr<T>& t, F&& f) -> decltype(typeTrait<decltype(f(*t))>::ret()) {
115 return t ? f(*t) : typeTrait<decltype(f(*t))>::ret();
116 }
117
118 template <typename T, typename F>
119 auto operator->*(const tstr<T>& t, F&& f) -> decltype(typeTrait<decltype(f(*t))>::ret()) {
120 return t ? f(*t) : typeTrait<decltype(f(*t))>::ret();
121 }
122
123 template <typename T, typename F>
124 auto operator->*(tstr<T>&& t, F&& f) -> decltype(typeTrait<decltype(f(*t))>::ret()) {
125 return t ? f(*t) : typeTrait<decltype(f(*t))>::ret();
126 }
127} // 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
tstr(const type &subtype)
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