5#if !defined(__XTD_CORE_INTERNAL__)
6#error "Do not include this file: Internal use only"
13 template<
typename type_t,
typename bool_t>
14 struct __enum_any_object__ {};
16 template<
typename type_t>
17 struct __enum_any_object__<type_t, std::true_type> {
18 auto operator()(
const any_object& o)
const -> type_t {
return as<enum_object<type_t>>(
o.value());}
21 template<
typename type_t>
22 struct __enum_any_object__<type_t, std::false_type> {
26 template<
typename type_t,
typename bool_t>
27 struct __polymorphic_any_object__ {};
29 template<
typename type_t>
30 struct __polymorphic_any_object__<type_t, std::true_type> {
31 auto operator()(
const any_object& o)
const -> type_t {
return as<type_t>(
o.value());}
34 template<
typename type_t>
35 struct __polymorphic_any_object__<type_t, std::false_type> {
36 auto operator()(
const any_object& o)
const -> type_t {
return __enum_any_object__<type_t, typename std::is_enum<type_t>::type> {}(
o);}
58 template<
typename type_t>
59 requires (!std::integral<type_t> || std::same_as<type_t, bool>)
62 return __polymorphic_any_object__<type_t, typename std::is_polymorphic<type_t>::type> {}(
o);
66 template<
typename type_t>
67 requires (std::integral<type_t> && !std::same_as<type_t, bool>)
68 [[nodiscard]]
inline auto as(any_object& o) -> type_t {
107 template<
typename type_t>
111 return __polymorphic_any_object__<type_t, typename std::is_polymorphic<type_t>::type> {}(
o);
115 template<
typename type_t>
117 [[nodiscard]]
inline auto as(
const any_object& o) -> type_t {
188 return const_cast<char*
>(
dynamic_cast<const xtd::string*
>(&value.value())->c_str());
191 [[nodiscard]]
inline auto as<char*>(
const xtd::any_object& value) ->
char* {
193 return const_cast<char*
>(
dynamic_cast<const xtd::string*
>(&
value.value())->c_str());
196 [[nodiscard]]
inline auto as<const char*>(xtd::any_object& value) ->
const char* {
201 [[nodiscard]]
inline auto as<const char*>(
const xtd::any_object& value) ->
const char* {
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:30
auto c_str() const noexcept -> const_pointer
Returns a pointer to a null-terminated character array with data equivalent to those stored in the st...
Definition basic_string.hpp:336
Represents a boxed integer object.
Definition box_integer.hpp:55
static auto to_string(xtd::any value) -> xtd::string
Convert xtd::any to string.
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Definition integer.hpp:12
@ value
Represnets the constant operator precedence (42).
Definition operator_precedence.hpp:30
@ invalid_cast
The cast is not valid.
Definition exception_case.hpp:63
xtd::basic_string< xtd::char8 > u8string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:76
xtd::basic_string< xtd::char32 > u32string
Represents text as a sequence of UTF-32 code units.
Definition __string_definitions.hpp:65
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
xtd::basic_string< xtd::char16 > u16string
Represents text as a sequence of UTF-16 code units.
Definition __string_definitions.hpp:54
xtd::basic_string< xtd::wchar > wstring
Represents text as a sequence of UTF-16 code unit on Windows or UTF-32 code unit on non-Windows syste...
Definition __string_definitions.hpp:87
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
null_ptr null
Represents a null pointer value.
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
std::nullptr_t null_ptr
Represents the null_opt alias on std::nullptr_t.
Definition null_ptr.hpp:19
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:23
auto as(any_object &o) -> type_t
Casts a type into another type.
Definition __as_any_object.hpp:60
auto is(xtd::any value) -> bool
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:485
@ integer
Indicates that the allow_leading_white, allow_trailing_white, and allow_leading_sign styles are used....
Definition number_styles.hpp:44
@ o
The O key.
Definition console_key.hpp:116
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
auto operator()(size_type index) const -> const_reference
Gets the element at the specified zero-based index.
Definition read_only_span.hpp:401
Represents a boxed object.
Definition box.hpp:55
value_type value
Gets or sets the underlying value.
Definition box.hpp:105