@@ -74,7 +74,8 @@ class SafePtr
74
74
// . no operator*() since T& is unsafe
75
75
shared_ptr<T> get () const noexcept { return pT_; }
76
76
shared_ptr<T> operator ->() const noexcept { return pT_; } // convenient
77
- auto use_count () const noexcept { return pT_.use_count (); }
77
+ explicit operator bool () const noexcept { return pT_ != nullptr ; }
78
+ auto use_count () const noexcept { return pT_.use_count (); }
78
79
79
80
// most for debug
80
81
auto realType () const noexcept { return realType_; } // ret cp is safer than ref
@@ -190,7 +191,7 @@ template<typename U, typename... ConstructArgs>
190
191
SafePtr<U> make_safe (ConstructArgs&&... aArgs)
191
192
{
192
193
SafePtr<U> safeU;
193
- safeU.pT_ = make_shared<U>(forward<ConstructArgs>(aArgs)...);
194
+ safeU.pT_ = std:: make_shared<U>(std:: forward<ConstructArgs>(aArgs)...); // std::~, or ambiguous with boost::~
194
195
// HID("new ptr=" << (void*)(safeU.pT_.get())); // too many print; void* print addr rather than content(dangeous)
195
196
return safeU;
196
197
}
@@ -241,6 +242,12 @@ struct std::hash<RLib::SafePtr<T>>
241
242
// . SafePtr is simple
242
243
// . freq cast void->any is dangeous
243
244
// . so worth
245
+ // . get()/etc ret shared_ptr<T>, safe?
246
+ // . safer than ret T* since still under lifecycle-protect
247
+ // . but not perfect as T* still available
248
+ // . this is the simplest way to call T's func - compromise convenient & safe
249
+ // . still worth? better than shared_ptr?
250
+ // . not perfect, but SafePtr inc safe than shared_ptr - eg create, cast - so worth
244
251
//
245
252
// . std::any vs SafePtr
246
253
// . SafePtr is safe shared_ptr that is lifecycle ptr, std::any is not ptr nor lifecycle mgmt
0 commit comments