xtd 0.2.0
as.hpp
Go to the documentation of this file.
1
3#pragma once
4#include "any.hpp"
7#include "types.hpp"
8#include <memory>
9#define __XTD_CORE_INTERNAL__
12#undef __XTD_CORE_INTERNAL__
13#include "convert.hpp"
14#define __XTD_CORE_INTERNAL__
35#undef __XTD_CORE_INTERNAL__
36#include "convert_pointer.hpp"
37#define __XTD_CORE_INTERNAL__
39#undef __XTD_CORE_INTERNAL__
40#include "convert_string.hpp"
41#define __XTD_CORE_INTERNAL__
43#undef __XTD_CORE_INTERNAL__
44#include "any_object.hpp"
45#include "enum_object.hpp"
46#define __XTD_CORE_INTERNAL__
48#undef __XTD_CORE_INTERNAL__
49#include "linq/enumerable.hpp"
50#define __XTD_CORE_INTERNAL__
52#undef __XTD_CORE_INTERNAL__
53
55template<class new_type_t, class current_type_t>
56new_type_t* __convert_value__(current_type_t* value) {
57 return xtd::as<new_type_t>(value);
58}
59
60template<class result_t, class source_t>
62 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
63 result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
64 for (const auto& item : source)
65 result.items.push_back(xtd::as<result_t>(item));
66 return static_cast<const xtd::collections::generic::ienumerable<result_t>&>(result);
67}
68
69template<class type_t>
70template<typename target_t>
73 return xtd::as<target_t>(to_object());
74}
75
76template<class type_t>
77template<typename target_t>
79 if (to_pointer() == null) return null;
80 return xtd::as<target_t>(to_pointer());
81}
82
83namespace std {
84 template<class type_t>
85 type_t any_cast(const xtd::any_object& value) {return xtd::as<type_t>(value);}
86 template<class type_t>
87 type_t any_cast(xtd::any_object& value) {return xtd::as<type_t>(value);}
88}
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 std::any type and std::bad_any_cast exception.
Contains xtd::any_object class.
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:29
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 const ienumerable< result_t > & 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 noexcept
Gets the stored object.
Definition shared_ptr_object.hpp:165
type_t * to_pointer() const noexcept
Gets the stored pointer.
Definition shared_ptr_object.hpp:175
Contains xtd::convert class.
Contains xtd::convert class.
Contains xtd::convert_string class.
Contains xtd::enum_object struct.
@ null_pointer
The pointer is null.
null_ptr null
Represents a null pointer value.
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
Contains xtd::invalid_cast_exception exception.
Contains xtd::linq::enumerable <type_t> class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::shared_ptr_object class.
Contains xtd fundamental types.