6#define __XTD_CORE_INTERNAL__
10#undef __XTD_CORE_INTERNAL__
41 template<
class type_t,
class deleter_t>
42 class unique_ptr_object :
public xtd::object,
public xtd::icomparable<unique_ptr_object<type_t, deleter_t>>,
public xtd::iequatable<unique_ptr_object<type_t, deleter_t >> {
48 using base_type = std::unique_ptr<type_t, deleter_t>;
50 using deleter_type =
typename base_type::deleter_type;
52 using element_type =
typename base_type::element_type;
54 using pointer_type =
typename base_type::pointer;
61 static const unique_ptr_object
empty;
68 unique_ptr_object() noexcept = default;
71 unique_ptr_object(xtd::null_ptr null) noexcept : ptr_ {
null} {}
74 explicit unique_ptr_object(pointer_type ptr) noexcept : ptr_ {
ptr} {}
78 unique_ptr_object(pointer_type ptr,
const deleter_t& deleter) noexcept : ptr_ {
ptr, deleter} {}
82 unique_ptr_object(pointer_type ptr, deleter_t&& deleter) noexcept : ptr_ {
ptr, deleter} {}
85 unique_ptr_object(unique_ptr_object&& value) noexcept : ptr_ {std::move(value.ptr_)} {}
88 template<
class value_t,
class other_deleter_t>
89 unique_ptr_object(unique_ptr_object<value_t, other_deleter_t>&& value) : ptr_ {std::move(value)} {}
92 template<
class value_t,
class other_deleter_t>
93 unique_ptr_object(std::unique_ptr<value_t, other_deleter_t>&& value) : ptr_ {std::move(value)} {}
96 unique_ptr_object(
const unique_ptr_object& value) =
delete;
99 unique_ptr_object(
const base_type& value) =
delete;
103 template<
class po
inter_t>
104 explicit unique_ptr_object(pointer_t* ptr) noexcept : ptr_ {
ptr} {}
108 template<
class po
inter_t,
class other_deleter_t>
109 unique_ptr_object(pointer_t* ptr, other_deleter_t deleter) noexcept : ptr_ {
ptr, deleter} {}
113 template<
class value_t>
114 unique_ptr_object(unique_ptr_object<value_t>&& value) noexcept : ptr_ {std::move(value.ptr_)} {}
117 unique_ptr_object(base_type&& value) noexcept : ptr_ {std::move(value)} {}
120 template<
class value_t>
121 unique_ptr_object(std::unique_ptr<value_t>&& value) noexcept : ptr_ {std::move(value)} {}
129 const base_type& pointer() const noexcept {
return ptr_;}
132 base_type& pointer() noexcept {
return ptr_;}
148 int32 compare_to(
const unique_ptr_object& obj)
const noexcept override {
return to_pointer() < obj.to_pointer() ? -1 : to_pointer() > obj.to_pointer() ? 1 : 0;}
153 bool equals(
const xtd::object& value)
const noexcept override {
return dynamic_cast<const unique_ptr_object*
>(&value) &&
equals(
static_cast<const unique_ptr_object&
>(value));}
157 bool equals(
const unique_ptr_object& value)
const noexcept override {
return ptr_ == value.ptr_;}
161 element_type* get() const noexcept {
return ptr_.get();}
169 pointer_type
release() noexcept {
return ptr_.release();}
173 void reset() noexcept {ptr_.reset();}
177 void reset(pointer_type ptr)
noexcept {ptr_.reset(ptr);}
181 template<
class po
inter_t>
182 void reset(pointer_t* ptr)
noexcept {ptr_.reset(ptr);}
190 void swap(unique_ptr_object& ptr)
noexcept {ptr_.swap(
ptr.ptr_);}
194 type_t& to_object() const noexcept {
return *to_pointer();}
199 template<
typename target_t>
200 target_t to_object()
const;
204 element_type* to_pointer() const noexcept {
return get();}
209 template<
typename target_t>
210 target_t* to_pointer()
const;
222 unique_ptr_object& operator =(unique_ptr_object&& value) noexcept {
223 ptr_ = std::move(value.ptr_);
229 template<
class value_t>
230 unique_ptr_object& operator =(unique_ptr_object<value_t>&& value)
noexcept {
231 ptr_ = std::move(value.ptr_);
237 template<
class value_t>
238 unique_ptr_object& operator =(std::unique_ptr<value_t>&& value)
noexcept {
239 ptr_ = std::move(value);
245 type_t& operator *() const noexcept {
return ptr_.operator * ();}
249 type_t* operator ->() const noexcept {
return ptr_.operator ->();}
254 element_type& operator[](std::ptrdiff_t index)
const {
return ptr_.operator [](index);}
258 explicit operator bool() const noexcept {
return ptr_.operator bool();}
262 template<
class value_t,
class other_deleter_t>
263 friend class xtd::unique_ptr_object;
265 template<
class value_t,
class allocator_t>
266 friend class xtd::basic_array;
268 template<
class value_t,
class allocator_t>
269 friend class xtd::collections::generic::list;
271 friend class xtd::linq::enumerable;
278 template<
class type_t,
class deleter_t>
279 inline const unique_ptr_object<type_t, deleter_t> unique_ptr_object<type_t, deleter_t>::empty;
285 template<
class type_t>
286 unique_ptr_object(type_t*) -> unique_ptr_object<type_t, std::default_delete<type_t>>;
287 template<
class type_t,
class deleter_t>
288 unique_ptr_object(type_t*,
const deleter_t&) -> unique_ptr_object<type_t, deleter_t>;
289 template<
class type_t,
class deleter_t>
290 unique_ptr_object(xtd::unique_ptr_object<type_t, deleter_t>()) -> unique_ptr_object<type_t, deleter_t>;
291 template<
class type_t,
class deleter_t>
292 unique_ptr_object(std::unique_ptr<type_t, deleter_t>()) -> unique_ptr_object<type_t, deleter_t>;
296template<
class object_t>
298 auto object_ptr =
dynamic_cast<const object_t*
>(
this);
300 return xtd::unique_ptr_object<object_t>(
new object_t(*object_ptr));
Contains xtd::array definitions.
Contains xtd::collections::generic::list definitions.
Contains xtd::unique_ptr_object definition.
static xtd::size combine(args_t... values) noexcept
Combines values into a hash code.
Definition hash_code.hpp:70
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:58
xtd::unique_ptr_object< object_t > memberwise_clone() const
Creates a shallow copy of the current object.
@ invalid_cast
The cast is not valid.
Definition exception_case.hpp:61
@ invalid_operation
The operation is not valid.
Definition exception_case.hpp:63
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
null_ptr null
Represents a null pointer value.
std::nullptr_t null_ptr
Represents the null_opt alias on std::nullptr_t.
Definition null_ptr.hpp:19
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
@ release
Build type release.
Definition build_type.hpp:24
Contains xtd::hash_code class.
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).
Definition enumerable.hpp:41
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:272
constexpr bool empty() const noexcept
Returns a value that indicates whether the current xtd::read_only_span <type_t> is empty.
Definition read_only_span.hpp:205
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:296
Contains xtd::null_ptr alias.
Contains xtd::object class.
Contains xtd::helpers::exception_case enum class.