37#ifndef LA_DECLSPEC_EMPTY_BASES
39#define LA_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
41#define LA_DECLSPEC_EMPTY_BASES
62template <
class T,
class Deleter,
class T2>
63struct LA_DECLSPEC_EMPTY_BASES compressed_ptr : std::unique_ptr<T, Deleter>, T2
65 using T1 = std::unique_ptr<T, Deleter>;
66 compressed_ptr() =
default;
67 compressed_ptr(compressed_ptr&&) =
default;
68 compressed_ptr(
const compressed_ptr&) =
default;
69 compressed_ptr(T2&& a2)
72 compressed_ptr(
const T2& a2)
75 template <
typename A1>
76 compressed_ptr(A1&& a1)
79 class_tag<typename std::decay<A1>::type>(),
83 template <
typename A1,
typename A2>
84 compressed_ptr(A1&& a1, A2&& a2)
88 class_tag<typename std::decay<A2>::type>(),
91 template <
typename A1,
typename A2,
typename A3>
92 compressed_ptr(A1&& a1, A2&& a2, A3&& a3)
93 : T1(std::forward<A1>(a1), std::forward<A2>(a2))
94 , T2(std::forward<A3>(a3))
97 template <
typename A1>
98 compressed_ptr(A1&& a1, class_tag<
typename std::decay<A1>::type>, spacer, spacer)
99 : T1(std::forward<A1>(a1))
101 template <
typename A1,
typename A2>
102 compressed_ptr(A1&& a1, A2&& a2, class_tag<Deleter>, spacer)
103 : T1(std::forward<A1>(a1), std::forward<A2>(a2))
105 template <
typename A1,
typename A2>
106 compressed_ptr(A1&& a1, A2&& a2, class_tag<T2>, spacer)
107 : T1(std::forward<A1>(a1))
108 , T2(std::forward<A2>(a2))
117 default_clone() =
default;
118 T* operator()(T
const& x)
const {
return new T(x); }
119 T* operator()(T&& x)
const {
return new T(std::move(x)); }
132template <
class T,
class Cloner = default_clone<T>,
class Deleter = std::default_delete<T>>
135 ::lagrange::detail::compressed_ptr<T, Deleter, Cloner> ptr_;
137 std::unique_ptr<T, Deleter>& ptr() {
return ptr_; }
138 std::unique_ptr<T, Deleter>
const& ptr()
const {
return ptr_; }
140 T* clone(T
const& x)
const {
return get_cloner()(x); }
144 using element_type = T;
145 using cloner_type = Cloner;
146 using deleter_type = Deleter;
151 : ptr_(cloner_type()(value))
154 : ptr_(cloner_type()(std::move(value)))
164 template <
typename V,
typename ClonerOrDeleter>
165 value_ptr(V&& value, ClonerOrDeleter&& a2)
166 : ptr_(std::forward<V>(value), std::forward<ClonerOrDeleter>(a2))
169 template <
typename V,
typename C,
typename D>
170 value_ptr(V&& value, C&& cloner, D&& deleter)
171 : ptr_(std::forward<V>(value), std::forward<D>(deleter), std::forward<C>(cloner))
175 : ptr_{
nullptr, v.get_cloner()}
178 ptr().reset(clone(*v));
186 pointer release() {
return ptr().release(); }
188 T* get()
noexcept {
return ptr().get(); }
189 T
const* get()
const noexcept {
return ptr().get(); }
191 Cloner& get_cloner()
noexcept {
return ptr_; }
192 Cloner
const& get_cloner()
const noexcept {
return ptr_; }
194 Deleter& get_deleter()
noexcept {
return ptr_; }
195 Deleter
const& get_deleter()
const noexcept {
return ptr_; }
197 T& operator*() {
return *get(); }
198 T
const& operator*()
const {
return *get(); }
200 T
const* operator->()
const noexcept {
return get(); }
201 T* operator->()
noexcept {
return get(); }
205 ptr() = std::move(v.ptr());
206 get_cloner() = std::move(v.get_cloner());
212 ptr().reset(v.get_cloner()(*v));
213 get_cloner() = v.get_cloner();
217 operator bool()
const noexcept {
return !!ptr(); }
231template <
class T,
class...
Args>
234 return value_ptr<T>(
new T(std::forward<Args>(args)...));
Smart pointer with value semantics.
Definition: value_ptr.h:134
value_ptr< T > make_value_ptr(Args &&... args)
Helper function to create a value_ptr for a given type.
Definition: value_ptr.h:232
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: project.cpp:27