File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 7272//
7373// Future Ideas:
7474// * void support
75+ // * static/const/dynamic casts
7576// * strong_ref_ptr - a non-nullable ref_ptr variant
7677//
7778//
@@ -161,6 +162,9 @@ class ref_ptr : private std::shared_ptr<T> {
161162 std::shared_ptr<T> _as_shared_ptr_unsafe () && noexcept {
162163 return std::move (*this );
163164 }
165+ static ref_ptr<T> _from_shared_ptr_unsafe (std::shared_ptr<T> ptr) noexcept {
166+ return ref_ptr<T>(std::move (ptr));
167+ }
164168};
165169
166170template <typename T, typename ... Args>
@@ -173,4 +177,9 @@ auto make_ref_ptr_from(T&& obj) -> ref_ptr<typename std::remove_reference<T>::ty
173177 return ref_ptr<typename std::remove_reference<T>::type>::make (std::forward<T>(obj));
174178}
175179
180+ template <typename T>
181+ ref_ptr<T> _ref_ptr_from_shared_ptr_unsafe (std::shared_ptr<T> ptr) noexcept {
182+ return ref_ptr<T>::_from_shared_ptr_unsafe (std::move (ptr));
183+ }
184+
176185} // namespace itlib
Original file line number Diff line number Diff line change @@ -93,3 +93,13 @@ TEST_CASE("poly") {
9393 CHECK (a >= d);
9494 CHECK_FALSE (a < d);
9595}
96+
97+ TEST_CASE (" unsafe" ) {
98+ auto sp = std::make_shared<int >(55 );
99+ auto rp = itlib::_ref_ptr_from_shared_ptr_unsafe (sp);
100+ CHECK (sp.get () == rp.get ());
101+ CHECK_FALSE (rp.unique ());
102+ auto sp2 = rp._as_shared_ptr_unsafe ();
103+ CHECK (sp == sp2);
104+ CHECK (rp.use_count () == 3 );
105+ }
You can’t perform that action at this time.
0 commit comments