xtd 0.2.0
Loading...
Searching...
No Matches
__as_any_object.h
Go to the documentation of this file.
1
3#pragma once
5#if !defined(__XTD_CORE_INTERNAL__)
6#error "Do not include this file: Internal use only"
7#endif
9
11namespace xtd {
12 template<typename type_t, typename bool_t>
14
15 template<typename type_t>
16 struct __enum_any_object__<type_t, std::true_type> {
17 type_t operator()(const any_object& o) const {return as<enum_object<type_t>>(o.value());}
18 };
19
20 template<typename type_t>
21 struct __enum_any_object__<type_t, std::false_type> {
22 type_t operator()(const any_object& o) const {throw invalid_cast_exception {csf_};}
23 };
24
25 template<typename type_t, typename bool_t>
27
28 template<typename type_t>
29 struct __polymorphic_any_object__<type_t, std::true_type> {
30 type_t operator()(const any_object& o) const {return as<type_t>(o.value());}
31 };
32
33 template<typename type_t>
34 struct __polymorphic_any_object__<type_t, std::false_type> {
35 type_t operator()(const any_object& o) const {return __enum_any_object__<type_t, typename std::is_enum<type_t>::type> {}(o);}
36 };
37
56 template<typename type_t>
57 type_t as(any_object& o) {
58 if (is<box<type_t>>(o.value())) return as<box<type_t>>(o.value()).value();
60 }
61
62 template<typename type_t>
63 type_t as(const any_object& o) {
64 if (is<box<type_t>>(o.value())) return as<box<type_t>>(o.value()).value();
65 return __polymorphic_any_object__<type_t, typename std::is_polymorphic<type_t>::type> {}(o);
66 }
67}
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.h:28
Represents a boxed object.
Definition box.h:53
The exception that is thrown for invalid casting or explicit conversion.
Definition invalid_cast_exception.h:18
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:365
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.h:57
@ o
The O key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Definition __as_any_object.h:13
Definition __as_any_object.h:26