14 template<
class T,
class Fin = finalize<T>>
15 class UniquePtr : mt::NoCopy
19 template<
class T_>
struct Elem_ {
typedef T_ type; };
20 template<
class T_>
struct Elem_<T_[]> {
typedef T_ type; };
21 template<class T_, bool = std::is_void<T_>::value>
struct Ref_ {
typedef T_& type;
static type deref(T_* p) {
return *p; } };
22 template<
class T_>
struct Ref_<T_, true> {
typedef T_ type;
static type deref(T_* p) {} };
25 typedef typename Elem_<T>::type
Elem;
26 typedef typename Ref_<Elem>::type
Ref;
31 template<
class Fin_ = Fin>
32 explicit UniquePtr(Ptr ptr, Fin_&& f = Fin_()) : _ptr(ptr), _fin(forward<Fin_>(f)) {}
35 template<
class U,
class F>
42 template<
class U,
class F>
45 template<
class U,
class F>
47 template<
class U,
class F>
49 template<
class U,
class F>
50 bool operator< (const UniquePtr<U,F>& rhs)
const {
return std::less<typename std::common_type<Ptr, typename UniquePtr<U,F>::Ptr>::type>()(
get(), rhs.get()); }
51 template<
class U,
class F>
53 template<
class U,
class F>
54 bool operator<=(const UniquePtr<U,F>& rhs)
const {
return !
operator>(rhs); }
55 template<
class U,
class F>
60 operator Ptr()
const {
return _ptr; }
63 Ptr
get()
const {
return _ptr; }
70 Ptr
release() { Ptr tmp = _ptr; _ptr =
nullptr;
return tmp; }
90 template<
class T,
class Alloc,
class... Args,
class Fin = finalize<T,typename mt::removeRef<Alloc>::type>>
98 template<
class T,
class... Args,
typename std::enable_if<std::is_array<T>::value,
int>::type=0>
102 template<
class T,
class... Args,
typename std::enable_if<std::is_array<T>::value,
int>::type=0>
112 template<
class T,
class Fin>
113 struct hash<
honey::UniquePtr<T,Fin>>
UniquePtr()
Definition: UniquePtr.h:29
Ref operator*() const
Definition: UniquePtr.h:59
bool operator!=(const UniquePtr< U, F > &rhs) const
Definition: UniquePtr.h:48
Fin & finalizer()
Get the finalizer.
Definition: UniquePtr.h:66
UniquePtr(nullptr_t)
Definition: UniquePtr.h:30
void set(Ptr p)
Finalize old pointer and assign new. Does not finalize if old pointer is the same or null...
Definition: UniquePtr.h:73
Elem * Ptr
Definition: UniquePtr.h:27
UniquePtr< T, Fin > alloc_unique(Alloc &&a, Args &&...args)
Create a unique ptr to an object of type T constructed with args.
Definition: UniquePtr.h:91
UniquePtr< T > make_unique_auto_size(Args &&...args)
Create a unique ptr to an array with deduced size.
Definition: UniquePtr.h:103
UniquePtr< T > make_unique(szt size)
Create a unique ptr to an array of size number of elements.
Definition: UniquePtr.h:99
Elem_< T >::type Elem
Definition: UniquePtr.h:25
bool operator>=(const UniquePtr< U, F > &rhs) const
Definition: UniquePtr.h:56
UniquePtr(UniquePtr &&rhs) noexcept
Moves pointer and finalizer out of rhs. To set a new finalizer into rhs use move assign: rhs = Unique...
Definition: UniquePtr.h:34
size_t operator()(const honey::UniquePtr< T, Fin > &val) const
Definition: UniquePtr.h:115
Ptr get() const
Get the raw pointer to the object.
Definition: UniquePtr.h:63
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
bool operator<(const UniquePtr< U, F > &rhs) const
Definition: UniquePtr.h:50
UniquePtr & operator=(UniquePtr &&rhs)
Moves pointer and finalizer out of rhs.
Definition: UniquePtr.h:41
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
int size(const StdContainer &cont)
Safely get the size of a std container as a signed integer.
Definition: StdUtil.h:19
Ref_< Elem >::type Ref
Definition: UniquePtr.h:26
UniquePtr(UniquePtr< U, F > &&rhs)
Definition: UniquePtr.h:36
Ptr operator->() const
Definition: UniquePtr.h:58
bool operator==(const UniquePtr< U, F > &rhs) const
Definition: UniquePtr.h:46
Ptr release()
Give up ownership of pointer without finalizing and set to null.
Definition: UniquePtr.h:70
Pointer to a unique, non-shared, object. Finalizer is run upon destruction (deletes object by default...
Definition: SharedPtr.h:164
UniquePtr & operator=(UniquePtr< U, F > &&rhs)
Definition: UniquePtr.h:43
UniquePtr< T > make_unique(Args &&...args)
alloc_unique() using T::Allocator if available, otherwise std::allocator
Definition: UniquePtr.h:95
~UniquePtr()
Definition: UniquePtr.h:38
std::allocator< T > type
Definition: Allocator.h:152
Global Honeycomb namespace.
const Fin & finalizer() const
Definition: UniquePtr.h:67
bool operator>(const UniquePtr< U, F > &rhs) const
Definition: UniquePtr.h:52
UniquePtr(Ptr ptr, Fin_ &&f=Fin_())
Definition: UniquePtr.h:32