xtd 0.2.0
as.hpp
Go to the documentation of this file.
1
3#pragma once
4#include "any.hpp"
8#include "types.hpp"
9#include <memory>
10#define __XTD_CORE_INTERNAL__
13#undef __XTD_CORE_INTERNAL__
14#include "convert.hpp"
15#define __XTD_CORE_INTERNAL__
36#undef __XTD_CORE_INTERNAL__
37#include "convert_pointer.hpp"
38#define __XTD_CORE_INTERNAL__
40#undef __XTD_CORE_INTERNAL__
41#include "convert_string.hpp"
42#define __XTD_CORE_INTERNAL__
44#undef __XTD_CORE_INTERNAL__
45#include "any_object.hpp"
46#include "enum_object.hpp"
47#define __XTD_CORE_INTERNAL__
49#undef __XTD_CORE_INTERNAL__
50#include "linq/enumerable.hpp"
51#define __XTD_CORE_INTERNAL__
53#undef __XTD_CORE_INTERNAL__
54
56template<class new_type_t, class current_type_t>
57new_type_t* __convert_value__(current_type_t* value) {
58 return xtd::as<new_type_t>(value);
59}
60
61template<class result_t, class source_t>
63 auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
64 result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
65 for (const auto& item : source)
66 result.items.push_back(xtd::as<result_t>(item));
67 return result;
68}
69
70template<class type_t>
71template<typename target_t>
74 return xtd::as<target_t>(to_object());
75}
76
77template<class type_t>
78template<typename target_t>
81 return xtd::as<target_t>(to_reference());
82}
83
84template<class type_t>
85template<typename target_t>
86target_t xtd::shared_ptr_object<type_t>::to_object() const {
88 return xtd::as<target_t>(to_object());
89}
90
91template<class type_t>
92template<typename target_t>
93target_t* xtd::shared_ptr_object<type_t>::to_pointer() const {
94 if (to_pointer() == null) return null;
95 return xtd::as<target_t>(to_pointer());
96}
97
98template<class type_t, class deleter_t>
99template<typename target_t>
100target_t xtd::unique_ptr_object<type_t, deleter_t>::to_object() const {
102 return xtd::as<target_t>(to_object());
103}
104
105template<class type_t, class deleter_t>
106template<typename target_t>
107target_t* xtd::unique_ptr_object<type_t, deleter_t>::to_pointer() const {
108 if (to_pointer() == null) return null;
109 return xtd::as<target_t>(to_pointer());
110}
111
112template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
113inline void xtd::array<>::copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, xtd::size source_index, const array<destination_type_t, destination_rank, destination_allocator_t>& destination_array, xtd::size destination_index, xtd::size length) {
114 if (source_index + length > source_array.data_->items.size()) helpers::throw_helper::throws(xtd::helpers::exception_case::index_out_of_range);
115 if (destination_index + length > destination_array.data_->items.size()) helpers::throw_helper::throws(xtd::helpers::exception_case::index_out_of_range);
116 for (auto i = xtd::size {}; i < length; ++i)
117 destination_array.data_->items[destination_index + i] = as<destination_type_t>(source_array.data_->items[source_index + i]);
118}
119
120namespace std {
121 template<class type_t>
122 type_t any_cast(const xtd::any_object& value) {return xtd::as<type_t>(value);}
123 template<class type_t>
124 type_t any_cast(xtd::any_object& value) {return xtd::as<type_t>(value);}
125}
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as struct.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains xtd::as method.
Contains opaque_xtd_linq_enumerable_collection <type_t> struct.
Contains xtd::any type and std::bad_any_cast exception.
Contains xtd::any_object class.
static void copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::size length)
Copies a range of elements from an xtd::array starting at the first element and pastes them into anot...
Definition array_static.hpp:196
virtual size_type length() const noexcept
Definition basic_array.hpp:209
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
static auto cast(const ienumerable< source_t > &source) noexcept
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
type_t & to_object() const
Gets the stored object.
Definition reference_wrapper_object.hpp:228
type & to_reference() const
Gets the stored reference.
Definition reference_wrapper_object.hpp:238
Contains xtd::convert class.
Contains xtd::convert class.
Contains xtd::convert_string class.
Contains xtd::enum_object struct.
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:59
@ null_pointer
The pointer is null.
Definition exception_case.hpp:77
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
null_ptr null
Represents a null pointer value.
type_t any_cast(const xtd::any &operand)
Performs type-safe access to the contained object.
Definition any_cast.hpp:22
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ i
The I key.
Definition console_key.hpp:104
Contains xtd::invalid_cast_exception exception.
Contains xtd::linq::enumerable <type_t> class.
constexpr bool is_empty() const noexcept
Returns a value that indicates whether the current xtd::read_only_span <type_t> is empty.
Definition read_only_span.hpp:225
Contains xtd::reference_wrapper_object class.
Contains xtd::shared_ptr_object class.
Contains xtd fundamental types.