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