3#ifndef CUDA_BATTERY_ROOT_PTR_HPP
4#define CUDA_BATTERY_ROOT_PTR_HPP
17template <
class T,
class Allocator = standard_allocator>
29 template<
class U,
class Alloc>
33 : allocator(allocator), ptr(nullptr), root(true) {}
35 : allocator(allocator), ptr(nullptr), root(true) {}
39 : allocator(allocator), ptr(ptr), root(true) {}
47 : ptr(static_cast<T*>(from.ptr)), allocator(from.allocator), root(from.root)
53 : ptr(other.ptr), allocator(other.allocator), root(false)
57 if(root && ptr !=
nullptr) {
59 allocator.deallocate(ptr);
115 CUDA explicit operator bool()
const {
116 return ptr !=
nullptr;
130template<
class T,
class Alloc,
class... Args>
132 Alloc allocator(alloc);
133 T* ptr =
static_cast<T*
>(allocator.allocate(
sizeof(T)));
134 assert(ptr !=
nullptr);
135 if constexpr(std::is_constructible<T, Args&&...,
const Alloc&>{}) {
136 new(ptr) T(std::forward<Args>(args)..., allocator);
139 new(ptr) T(std::forward<Args>(args)...);
145template<
class T,
class Alloc,
class... Args>
Definition root_ptr.hpp:18
CUDA root_ptr & operator=(std::nullptr_t)
Definition root_ptr.hpp:87
CUDA allocator_type get_allocator() const
Definition root_ptr.hpp:107
CUDA root_ptr(std::nullptr_t, const allocator_type &allocator=allocator_type())
Definition root_ptr.hpp:34
T element_type
Definition root_ptr.hpp:20
CUDA root_ptr & operator=(const root_ptr &r)
Definition root_ptr.hpp:75
CUDA root_ptr(root_ptr< U, Allocator > &&from)
Definition root_ptr.hpp:46
CUDA bool is_root() const
Definition root_ptr.hpp:111
root_ptr< element_type, allocator_type > this_type
Definition root_ptr.hpp:23
CUDA NI ~root_ptr()
Definition root_ptr.hpp:56
CUDA root_ptr(pointer ptr, const allocator_type &allocator=allocator_type())
Definition root_ptr.hpp:38
T * pointer
Definition root_ptr.hpp:21
CUDA void reset(pointer ptr=pointer())
Definition root_ptr.hpp:99
CUDA root_ptr(const this_type &other)
Definition root_ptr.hpp:52
CUDA root_ptr & operator=(root_ptr &&r)
Definition root_ptr.hpp:70
CUDA pointer release()
Definition root_ptr.hpp:92
Allocator allocator_type
Definition root_ptr.hpp:22
CUDA root_ptr(const allocator_type &allocator=allocator_type())
Definition root_ptr.hpp:32
CUDA pointer get() const
Definition root_ptr.hpp:103
CUDA T & operator*() const
Definition root_ptr.hpp:119
CUDA root_ptr(this_type &&from)
Definition root_ptr.hpp:41
CUDA void swap(root_ptr &other)
Definition root_ptr.hpp:64
CUDA pointer operator->() const
Definition root_ptr.hpp:124
CUDA root_ptr & operator=(root_ptr< U, Allocator > &&r)
Definition root_ptr.hpp:82
Definition algorithm.hpp:10
CUDA NI root_ptr< T, Alloc > allocate_root(const Alloc &alloc, Args &&... args)
Definition root_ptr.hpp:131
CUDA constexpr void swap(T &a, T &b)
Definition utility.hpp:91
CUDA root_ptr< T, Alloc > make_root(Args &&... args)
Definition root_ptr.hpp:146
#define CUDA
Definition utility.hpp:59
#define NI
Definition utility.hpp:62