mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-03 16:30:29 +00:00
Handle unique_ptr
Also just use plain using statements, derp
This commit is contained in:
parent
f6fc17d2e5
commit
10f1d06415
2 changed files with 18 additions and 25 deletions
|
@ -102,8 +102,12 @@ class shared_pointer : public shared_ref
|
|||
public:
|
||||
static shared_pointer* make(T* const p, D d)
|
||||
{
|
||||
auto p2 = unique_ptr<T, D>(p, move(d));
|
||||
return new shared_pointer(p2.release(), move(p2.get_deleter()));
|
||||
return make(unique_ptr<T, D>(p, move(d)));
|
||||
}
|
||||
|
||||
static shared_pointer* make(unique_ptr<T, D> 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<typename U, typename D>
|
||||
requires is_convertible_v<U, T>
|
||||
shared_ptr(unique_ptr<U, D>&& r)
|
||||
: p(r.p), rc(__::shared_pointer<U, D>::make(r.release(), r.get_deleter()))
|
||||
: p(r.p), rc(__::shared_pointer<U, D>::make(move(r)))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
~shared_ptr()
|
||||
{
|
||||
|
|
|
@ -21,22 +21,16 @@
|
|||
#include "libc/mem/leaks.h"
|
||||
|
||||
// #include <memory>
|
||||
// #include <vector>
|
||||
// #define ctl std
|
||||
|
||||
template<typename T>
|
||||
using shared_ptr = ctl::shared_ptr<T>;
|
||||
|
||||
template<typename T>
|
||||
using weak_ptr = ctl::weak_ptr<T>;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T>
|
||||
make_shared(Args&&... args)
|
||||
{
|
||||
return ctl::make_shared<T, Args...>(ctl::forward<Args>(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<ctl::vector<int>> x(new ctl::vector<int>);
|
||||
shared_ptr<vector<int>> x(new vector<int>);
|
||||
x->push_back(5);
|
||||
shared_ptr<int> 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<int> y(ctl::move(x));
|
||||
unique_ptr<int, CallG> x(&a, CallG());
|
||||
shared_ptr<int> y(move(x));
|
||||
if (x)
|
||||
return 10;
|
||||
y.reset();
|
||||
if (g != 1)
|
||||
return 11;
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
g = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue