4 #include <bits/shared_ptr.h> 13 #ifndef JLE_SHARED_PTR_H 14 #define JLE_SHARED_PTR_H 1 20 template<
typename _Tp>
38 template<
typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
42 std::shared_ptr<_Tp> ptr;
61 template<
typename _Tp1>
79 template<
typename _Tp1,
typename _Deleter>
97 template<
typename _Deleter>
116 template<
typename _Tp1,
typename _Deleter,
typename _Alloc>
118 : ptr(__p, __d, __a) {}
135 template<
typename _Deleter,
typename _Alloc>
137 : ptr(__p, __d, __a) {}
162 std::shared_ptr<_Tp> __internal_dangerous__get_std_shared_ptr(
void)
const {
return ptr; }
171 template<
typename _Tp1,
typename =
typename 172 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
174 : ptr(
std::
shared_ptr<_Tp>(__r.__internal_dangerous__get_std_shared_ptr())) {}
198 template<
typename _Tp1,
typename =
typename 199 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
212 template<
typename _Tp1>
216 template<
typename _Tp1,
typename _Del>
228 explicit shared_ptr(
const std::shared_ptr<_Tp>& _ptr)
233 template<
typename _Tp1>
257 template<
typename _Tp1,
typename _Del>
259 operator=(std::unique_ptr<_Tp1, _Del>&& __r)
276 template<
typename _Tp1>
281 template<
typename _Tp1,
typename _Deleter>
283 reset(_Tp1* __p, _Deleter __d)
284 { ptr.reset(__p, __d); }
286 template<
typename _Tp1,
typename _Deleter,
typename _Alloc>
288 reset(_Tp1* __p, _Deleter __d, _Alloc __a)
289 { ptr.reset(__p, __d, __a); }
293 typename std::add_lvalue_reference<_Tp>::type
308 bool expired(
void)
const {
309 return ((ptr.get()==
nullptr) ?
true:
false);
319 explicit operator bool()
const 320 {
return bool(ptr); }
324 {
return ptr.unique(); }
328 {
return ptr.use_count(); }
331 swap(std::__shared_ptr<_Tp, _Lp>& __other)
336 template<
typename _Tp1>
338 owner_before(std::__shared_ptr<_Tp1, _Lp>
const& __rhs)
const 339 {
return ptr.owner_before(__rhs); }
341 template<
typename _Tp1>
343 owner_before(std::__weak_ptr<_Tp1, _Lp>
const& __rhs)
const 344 {
return ptr.owner_before(__rhs); }
393 void check_ptr(
void)
const 396 throw std::runtime_error(
"shared_ptr pointer not valid");
417 template<
typename _Tp1,
typename _Tp2>
421 {
return __a.get() == __b.get(); }
423 template<
typename _Tp>
428 template<
typename _Tp>
433 template<
typename _Tp1,
typename _Tp2>
437 {
return __a.get() != __b.get(); }
439 template<
typename _Tp>
442 {
return (
bool)__a; }
444 template<
typename _Tp>
447 {
return (
bool)__a; }
449 template<
typename _Tp1,
typename _Tp2>
451 operator<(const shared_ptr<_Tp1>& __a,
454 typedef typename std::common_type<_Tp1*, _Tp2*>::type _CT;
455 return std::less<_CT>()(__a.get(), __b.get());
458 template<
typename _Tp>
460 operator<(const shared_ptr<_Tp>& __a, nullptr_t)
461 {
return std::less<_Tp*>()(__a.get(),
nullptr); }
463 template<
typename _Tp>
465 operator<(nullptr_t, const shared_ptr<_Tp>& __a)
466 {
return std::less<_Tp*>()(
nullptr, __a.get()); }
468 template<
typename _Tp1,
typename _Tp2>
470 operator<=(const shared_ptr<_Tp1>& __a,
472 {
return !(__b < __a); }
474 template<
typename _Tp>
476 operator<=(const shared_ptr<_Tp>& __a, nullptr_t)
477 {
return !(
nullptr < __a); }
479 template<
typename _Tp>
481 operator<=(nullptr_t, const shared_ptr<_Tp>& __a)
482 {
return !(__a <
nullptr); }
484 template<
typename _Tp1,
typename _Tp2>
488 {
return (__b < __a); }
490 template<
typename _Tp>
493 {
return std::less<_Tp*>()(
nullptr, __a.get()); }
495 template<
typename _Tp>
498 {
return std::less<_Tp*>()(__a.get(),
nullptr); }
500 template<
typename _Tp1,
typename _Tp2>
504 {
return !(__a < __b); }
506 template<
typename _Tp>
509 {
return !(__a <
nullptr); }
511 template<
typename _Tp>
514 {
return !(
nullptr < __a); }
521 template<
typename _Tp>
527 template<
typename _Tp,
typename _Tp1>
532 template<
typename _Tp,
typename _Tp1>
537 template<
typename _Tp,
typename _Tp1>
541 if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
566 template<
typename _Tp>
570 std::weak_ptr<_Tp> ptr;
571 void check_ptr(
void)
const 574 throw std::runtime_error(
"shared_ptr pointer not valid");
581 template<
typename _Tp1,
typename =
typename 582 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
586 template<
typename _Tp1,
typename =
typename 587 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
591 template<
typename _Tp1>
599 template<
typename _Tp1>
618 bool expired(
void)
const {
619 return ptr.expired();
625 template<
typename _Tp>
632 template<
typename _Tp>
636 template<
typename _Tp>
638 :
public std::_Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
642 template<
typename _Tp>
644 :
public std::_Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
650 template<
typename _Tp>
670 shared_from_this()
const 674 template<
typename _Tp1>
676 _M_weak_assign(_Tp1* __p,
const std::__shared_count<>& __n)
const 677 { _M_weak_this._M_assign(__p, __n); }
679 template<
typename _Tp1>
681 __enable_shared_from_this_helper(
const std::__shared_count<>& __pn,
686 __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);
718 template<
typename _Tp,
typename... _Args>
722 std::shared_ptr<_Tp> ptr = std::make_shared<_Tp>(__args...);
745 #endif // JLE_SHARED_PTR_H shared_ptr(_Tp1 *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
Definition: shared_ptr.hpp:80
Definition: http_server.h:9
shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns a null pointer and the deleter __d.
Definition: shared_ptr.hpp:136
constexpr shared_ptr()
Construct an empty shared_ptr.
Definition: shared_ptr.hpp:50
shared_ptr< _Tp > make_shared(_Args &&...__args)
Create an object that is owned by a shared_ptr.
Definition: shared_ptr.hpp:720
Base class allowing use of member function shared_from_this.
Definition: shared_ptr.hpp:651
shared_ptr(const shared_ptr< _Tp1 > &__r)
If __r is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownersh...
Definition: shared_ptr.hpp:173
shared_ptr(const weak_ptr< _Tp1 > &__r)
Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r...
Definition: shared_ptr.hpp:213
shared_ptr(std::shared_ptr< _Tp > &&__ptr)
Move-constructs a shared_ptr instance from __r.
Definition: shared_ptr.hpp:190
shared_ptr(_Tp1 *__p)
Construct a shared_ptr that owns the pointer __p.
Definition: shared_ptr.hpp:62
shared_ptr(shared_ptr< _Tp1 > &&__r)
Move-constructs a shared_ptr instance from __r.
Definition: shared_ptr.hpp:200
shared_ptr(shared_ptr &&__r)
Move-constructs a shared_ptr instance from __r.
Definition: shared_ptr.hpp:181
A safe std smart pointer WRAPPER.
Definition: shared_ptr.hpp:39
constexpr shared_ptr(nullptr_t __p)
Construct an empty shared_ptr.
Definition: shared_ptr.hpp:225
A safe std weak_ptr WRAPPER.
Definition: shared_ptr.hpp:21
shared_ptr(nullptr_t __p, _Deleter __d)
Construct a shared_ptr that owns a null pointer and the deleter __d.
Definition: shared_ptr.hpp:98
shared_ptr(_Tp1 *__p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
Definition: shared_ptr.hpp:117
Primary template owner_less.
Definition: shared_ptr.hpp:633
generic namespace
Definition: alarm.cpp:12