diff --git a/ctl/shared_ptr.h b/ctl/shared_ptr.h index cc31cf231..d05dad900 100644 --- a/ctl/shared_ptr.h +++ b/ctl/shared_ptr.h @@ -102,8 +102,12 @@ class shared_pointer : public shared_ref public: static shared_pointer* make(T* const p, D d) { - auto p2 = unique_ptr(p, move(d)); - return new shared_pointer(p2.release(), move(p2.get_deleter())); + return make(unique_ptr(p, move(d))); + } + + static shared_pointer* make(unique_ptr p) + { + return new shared_pointer(p.release(), move(p.get_deleter())); } private: @@ -235,15 +239,12 @@ class shared_ptr rc->keep_shared(); } - // TODO(mrdomino): blocked on ctl::ref -#if 0 template requires is_convertible_v shared_ptr(unique_ptr&& r) - : p(r.p), rc(__::shared_pointer::make(r.release(), r.get_deleter())) + : p(r.p), rc(__::shared_pointer::make(move(r))) { } -#endif ~shared_ptr() { diff --git a/test/ctl/shared_ptr_test.cc b/test/ctl/shared_ptr_test.cc index c8cf3f536..312f1d167 100644 --- a/test/ctl/shared_ptr_test.cc +++ b/test/ctl/shared_ptr_test.cc @@ -21,22 +21,16 @@ #include "libc/mem/leaks.h" // #include +// #include // #define ctl std -template -using shared_ptr = ctl::shared_ptr; - -template -using weak_ptr = ctl::weak_ptr; - -template -shared_ptr -make_shared(Args&&... args) -{ - return ctl::make_shared(ctl::forward(args)...); -} - -using bad_weak_ptr = ctl::bad_weak_ptr; +using ctl::bad_weak_ptr; +using ctl::make_shared; +using ctl::move; +using ctl::shared_ptr; +using ctl::unique_ptr; +using ctl::vector; +using ctl::weak_ptr; #undef ctl @@ -149,7 +143,7 @@ main() { // You can take a shared pointer to a subobject, and it will free the // base object. - shared_ptr> x(new ctl::vector); + shared_ptr> x(new vector); x->push_back(5); shared_ptr y(x, &x->at(0)); x.reset(); @@ -157,19 +151,17 @@ main() return 9; } -#if 0 { g = 0; // You can create a shared_ptr from a unique_ptr. - ctl::unique_ptr x(&a, CallG()); - shared_ptr y(ctl::move(x)); + unique_ptr x(&a, CallG()); + shared_ptr y(move(x)); if (x) return 10; y.reset(); if (g != 1) return 11; } -#endif { g = 0;