7 #pragma warning(disable : 4365 4987)
16template<
class T,
class B = T>
18 template<
typename ... Args>
20 return new T{std::forward<Args>(args)...};
25template<
class T,
class B = T>
30 #if !defined(__clang__) && defined(__GNUC__)
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wsign-conversion"
34 using complete_type_checker =
char[
sizeof(T) ? 1 : -1];
35 #if !defined(__clang__) && defined(__GNUC__)
36 #pragma GCC diagnostic pop
38 static_cast<void>(
sizeof(complete_type_checker));
57 #if !defined(__clang__) && defined(__GNUC__)
58 #pragma GCC diagnostic push
59 #pragma GCC diagnostic ignored "-Wsign-conversion"
61 using complete_type_checker =
char[
sizeof(T) ? 1 : -1];
62 #if !defined(__clang__) && defined(__GNUC__)
63 #pragma GCC diagnostic pop
65 static_cast<void>(
sizeof(complete_type_checker));
71template<
class T,
class B = T>
73 template<
typename ... Args>
75 return T::create(std::forward<Args>(args)...);
80template<
class T,
class B = T>
83 T::destroy(
static_cast<T*
>(ptr));
115template<class T, class TDestroyer = typename DefaultInstanceDestroyer<T>::type>
137 template<
typename U,
class UDestroyer>
152 destroyer_type::operator()(
ptr);
177 template<
typename U,
class UDestroyer>
183 template<
typename U,
class UDestroyer>
190 template<typename U = T, typename IA = typename inspect<U>::is_array>
191 typename std::enable_if<IA::value, element_type&>::type
operator[](std::size_t index)
const noexcept {
195 template<typename U = T, typename IA = typename inspect<U>::is_array>
196 typename std::enable_if<!IA::value, element_type&>::type
operator*() const noexcept {
204 operator bool() const noexcept {
205 return ptr !=
nullptr;
214 std::swap(result,
ptr);
222 destroyer_type::operator()(old);
228 std::swap(
ptr, rhs.ptr);
250template<
class T,
class TCreator,
class TDestroyer,
typename ... Args,
251 typename Base =
typename std::remove_pointer <
decltype(TCreator{} (std::declval<Args>()...)) > ::type>
253 static_assert(std::is_same<Base, T>::value ||
254 std::is_base_of<Base, T>::value ||
255 std::is_convertible<T, typename std::add_pointer<Base>::type>::value,
256 "Incompatible types.");
260template<
class T,
template<
class ...>
class TCreatorTemplate,
template<
class ...>
class TDestroyerTemplate,
typename ... Args>
262 using TCreator = TCreatorTemplate<T>;
263 using TDestroyer = TDestroyerTemplate<T>;
264 return makeScoped<T, TCreator, TDestroyer>(std::forward<Args>(args)...);
267template<
class T,
typename ... Args>
271 return makeScoped<T, TCreator, TDestroyer>(std::forward<Args>(args)...);
Takes ownership over the given pointer and handles it's lifetime.
Definition: ScopedPtr.h:116
ScopedPtr()
Definition: ScopedPtr.h:141
std::enable_if< IA::value, element_type & >::type operator[](std::size_t index) const noexcept
Definition: ScopedPtr.h:191
ScopedPtr & operator=(ScopedPtr &&rhs) noexcept
Definition: ScopedPtr.h:172
TDestroyer destroyer_type
Definition: ScopedPtr.h:135
pointer operator->() const noexcept
Definition: ScopedPtr.h:200
typename inspect< T >::pointer_type pointer
Definition: ScopedPtr.h:133
pointer get() const noexcept
Definition: ScopedPtr.h:208
~ScopedPtr()
Definition: ScopedPtr.h:150
void swap(ScopedPtr &rhs) noexcept
Definition: ScopedPtr.h:226
ScopedPtr & operator=(const ScopedPtr &)=delete
pointer ptr
Definition: ScopedPtr.h:232
ScopedPtr(std::nullptr_t)
Definition: ScopedPtr.h:157
typename inspect< T >::element_type element_type
Definition: ScopedPtr.h:134
ScopedPtr & operator=(std::nullptr_t)
Definition: ScopedPtr.h:160
void reset(pointer rhs=pointer()) noexcept
Definition: ScopedPtr.h:218
pointer release() noexcept
Definition: ScopedPtr.h:212
ScopedPtr & operator=(ScopedPtr< U, UDestroyer > &&rhs) noexcept
Definition: ScopedPtr.h:184
ScopedPtr(const ScopedPtr &)=delete
ScopedPtr(pointer ptr_, destroyer_type &&destroyer)
Definition: ScopedPtr.h:147
ScopedPtr(ScopedPtr &&rhs) noexcept
Definition: ScopedPtr.h:168
ScopedPtr(pointer ptr_)
Definition: ScopedPtr.h:144
std::enable_if<!IA::value, element_type & >::type operator*() const noexcept
Definition: ScopedPtr.h:196
ScopedPtr(ScopedPtr< U, UDestroyer > &&rhs) noexcept
Definition: ScopedPtr.h:178
Definition: BinaryStreamReader.h:121
ScopedPtr< Base, TDestroyer > makeScoped(Args &&... args)
Syntactic sugar for creating instances wrapped in a ScopedPtr.
Definition: ScopedPtr.h:252
Definition: ScopedPtr.h:89
Definition: ScopedPtr.h:94
void operator()(T *ptr)
Definition: ScopedPtr.h:54
Definition: ScopedPtr.h:26
void operator()(B *ptr)
Definition: ScopedPtr.h:27
Definition: ScopedPtr.h:72
B * operator()(Args &&... args)
Definition: ScopedPtr.h:74
Definition: ScopedPtr.h:81
void operator()(B *ptr)
Definition: ScopedPtr.h:82
T * operator()(std::size_t size)
Definition: ScopedPtr.h:46
Definition: ScopedPtr.h:17
B * operator()(Args &&... args)
Definition: ScopedPtr.h:19
element_type * pointer_type
Definition: ScopedPtr.h:128
U element_type
Definition: ScopedPtr.h:127
std::true_type is_array
Definition: ScopedPtr.h:129
Definition: ScopedPtr.h:119
std::false_type is_array
Definition: ScopedPtr.h:122
element_type * pointer_type
Definition: ScopedPtr.h:121
U element_type
Definition: ScopedPtr.h:120