10#define __XTD_CORE_INTERNAL__
11#include "internal/__as_enum.h"
12#undef __XTD_CORE_INTERNAL__
36 template<
typename new_type_t>
37 new_type_t
as(std::any value) {
39 return std::any_cast<new_type_t>(value);
40 }
catch (
const std::exception&
e) {
60 template<
typename new_type_t>
61 new_type_t
as(
bool value) {
62 return static_cast<new_type_t
>(value);
80 template<
typename new_type_t>
82 return static_cast<new_type_t
>(value);
100 template<
typename new_type_t>
101 new_type_t
as(
char value) {
102 return static_cast<new_type_t
>(value);
105#if defined(__cpp_lib_char8_t)
121 template<
typename new_type_t>
123 return static_cast<new_type_t
>(value);
142 template<
typename new_type_t>
144 return static_cast<new_type_t
>(value);
162 template<
typename new_type_t>
164 return static_cast<new_type_t
>(value);
182 template<
typename new_type_t>
184 return static_cast<new_type_t
>(value);
202 template<
typename new_type_t>
204 return static_cast<new_type_t
>(value);
222 template<
typename new_type_t>
223 new_type_t
as(
double value) {
224 return static_cast<new_type_t
>(value);
242 template<
typename new_type_t>
243 new_type_t
as(
float value) {
244 return static_cast<new_type_t
>(value);
262 template<
typename new_type_t>
264 return static_cast<new_type_t
>(value);
282 template<
typename new_type_t>
284 return static_cast<new_type_t
>(value);
302 template<
typename new_type_t>
304 return static_cast<new_type_t
>(value);
322 template<
typename new_type_t>
324 return static_cast<new_type_t
>(value);
342 template<
typename new_type_t>
344 return static_cast<new_type_t
>(value);
362 template<
typename new_type_t>
364 return static_cast<new_type_t
>(value);
382 template<
typename new_type_t>
384 return static_cast<new_type_t
>(value);
402 template<
typename new_type_t>
404 return static_cast<new_type_t
>(value);
422 template<
typename new_type_t>
424 return static_cast<new_type_t
>(value);
443 template<
typename new_type_t>
446 return dynamic_cast<const new_type_t&
>(value);
447 }
catch (
const std::exception&
e) {
450 throw std::bad_cast();
469 template<
typename new_type_t>
472 return dynamic_cast<new_type_t&
>(value);
473 }
catch (
const std::exception&
e) {
476 throw std::bad_cast();
480 template<
typename new_type_t>
482 throw invalid_cast_exception {
csf_};
484 template<
typename new_type_t>
486 throw invalid_cast_exception {
csf_};
488 template<
typename new_type_t>
490 throw invalid_cast_exception {
csf_};
492 template<
typename new_type_t>
494 throw invalid_cast_exception {
csf_};
496 template<
typename new_type_t>
498 throw invalid_cast_exception {
csf_};
500 template<
typename new_type_t>
502 throw invalid_cast_exception {
csf_};
504 template<
typename new_type_t>
506 throw invalid_cast_exception {
csf_};
508 template<
typename new_type_t>
510 throw invalid_cast_exception {
csf_};
512 template<
typename new_type_t>
514 throw invalid_cast_exception {
csf_};
516 template<
typename new_type_t>
518 throw invalid_cast_exception {
csf_};
520 template<
typename new_type_t>
522 throw invalid_cast_exception {
csf_};
537 template<
typename new_type_t>
538 new_type_t
as(
const std::string& value) {
540 return dynamic_cast<const new_type_t&
>(value);
541 }
catch (
const std::exception&
e) {
544 throw std::bad_cast();
558 template<
typename new_type_t>
559 new_type_t
as(std::string& value) {
561 return dynamic_cast<new_type_t&
>(value);
562 }
catch (
const std::exception&
e) {
565 throw std::bad_cast();
568#if defined(__cpp_lib_char8_t)
580 template<
typename new_type_t>
581 new_type_t
as(
const std::u8string& value) {
583 return dynamic_cast<const new_type_t&
>(value);
584 }
catch (
const std::exception&
e) {
587 throw std::bad_cast();
601 template<
typename new_type_t>
602 new_type_t
as(std::u8string& value) {
604 return dynamic_cast<new_type_t&
>(value);
605 }
catch (
const std::exception&
e) {
608 throw std::bad_cast();
623 template<
typename new_type_t>
624 new_type_t
as(
const std::u16string& value) {
626 return dynamic_cast<const new_type_t&
>(value);
627 }
catch (
const std::exception&
e) {
630 throw std::bad_cast();
644 template<
typename new_type_t>
645 new_type_t
as(std::u16string& value) {
647 return dynamic_cast<new_type_t&
>(value);
648 }
catch (
const std::exception&
e) {
651 throw std::bad_cast();
665 template<
typename new_type_t>
666 new_type_t
as(
const std::u32string& value) {
668 return dynamic_cast<const new_type_t&
>(value);
669 }
catch (
const std::exception&
e) {
672 throw std::bad_cast();
686 template<
typename new_type_t>
687 new_type_t
as(std::u32string& value) {
689 return dynamic_cast<new_type_t&
>(value);
690 }
catch (
const std::exception&
e) {
693 throw std::bad_cast();
707 template<
typename new_type_t>
708 new_type_t
as(
const std::wstring& value) {
710 return dynamic_cast<const new_type_t&
>(value);
711 }
catch (
const std::exception&
e) {
714 throw std::bad_cast();
728 template<
typename new_type_t>
729 new_type_t
as(std::wstring& value) {
731 return dynamic_cast<new_type_t&
>(value);
732 }
catch (
const std::exception&
e) {
735 throw std::bad_cast();
753 template<
typename new_type_t>
754 new_type_t
as(
const char* value) {
755 return reinterpret_cast<new_type_t
>(value);
773 template<
typename new_type_t>
774 new_type_t
as(
char* value) {
775 return reinterpret_cast<new_type_t
>(value);
778#if defined(__cpp_lib_char8_t)
794 template<
typename new_type_t>
796 return reinterpret_cast<new_type_t
>(value);
814 template<
typename new_type_t>
816 return reinterpret_cast<new_type_t
>(value);
835 template<
typename new_type_t>
837 return reinterpret_cast<new_type_t
>(value);
855 template<
typename new_type_t>
857 return reinterpret_cast<new_type_t
>(value);
875 template<
typename new_type_t>
877 return reinterpret_cast<new_type_t
>(value);
895 template<
typename new_type_t>
897 return reinterpret_cast<new_type_t
>(value);
915 template<
typename new_type_t>
917 return reinterpret_cast<new_type_t
>(value);
935 template<
typename new_type_t>
937 return reinterpret_cast<new_type_t
>(value);
1025#if defined(__cpp_lib_char8_t)
1393#if defined(__cpp_lib_char8_t)
1521#if defined(__cpp_lib_char8_t)
1773#if defined(__cpp_lib_char8_t)
2163#if defined(__cpp_lib_char8_t)
2291#if defined(__cpp_lib_char8_t)
2543#if defined(__cpp_lib_char8_t)
2911#if defined(__cpp_lib_char8_t)
3039#if defined(__cpp_lib_char8_t)
3209#if defined(__cpp_lib_char8_t)
4035#if defined(__cpp_lib_char8_t)
4403#if defined(__cpp_lib_char8_t)
4531#if defined(__cpp_lib_char8_t)
4783#if defined(__cpp_lib_char8_t)
5151#if defined(__cpp_lib_char8_t)
5279#if defined(__cpp_lib_char8_t)
5531#if defined(__cpp_lib_char8_t)
5899#if defined(__cpp_lib_char8_t)
6027#if defined(__cpp_lib_char8_t)
6279#if defined(__cpp_lib_char8_t)
6647#if defined(__cpp_lib_char8_t)
6775#if defined(__cpp_lib_char8_t)
7027#if defined(__cpp_lib_char8_t)
7395#if defined(__cpp_lib_char8_t)
7523#if defined(__cpp_lib_char8_t)
7775#if defined(__cpp_lib_char8_t)
8143#if defined(__cpp_lib_char8_t)
8271#if defined(__cpp_lib_char8_t)
8523#if defined(__cpp_lib_char8_t)
8913#if defined(__cpp_lib_char8_t)
9041#if defined(__cpp_lib_char8_t)
9293#if defined(__cpp_lib_char8_t)
9683#if defined(__cpp_lib_char8_t)
9811#if defined(__cpp_lib_char8_t)
10063#if defined(__cpp_lib_char8_t)
10453#if defined(__cpp_lib_char8_t)
10581#if defined(__cpp_lib_char8_t)
10833#if defined(__cpp_lib_char8_t)
11223#if defined(__cpp_lib_char8_t)
11351#if defined(__cpp_lib_char8_t)
11603#if defined(__cpp_lib_char8_t)
11993#if defined(__cpp_lib_char8_t)
12121#if defined(__cpp_lib_char8_t)
12373#if defined(__cpp_lib_char8_t)
12763#if defined(__cpp_lib_char8_t)
12891#if defined(__cpp_lib_char8_t)
13143#if defined(__cpp_lib_char8_t)
13533#if defined(__cpp_lib_char8_t)
13661#if defined(__cpp_lib_char8_t)
13913#if defined(__cpp_lib_char8_t)
14303#if defined(__cpp_lib_char8_t)
14431#if defined(__cpp_lib_char8_t)
14683#if defined(__cpp_lib_char8_t)
15073#if defined(__cpp_lib_char8_t)
15201#if defined(__cpp_lib_char8_t)
15475#if defined(__cpp_lib_char8_t)
16016 template<
typename new_type_t,
typename current_type_t>
16017 const new_type_t&
as(
const current_type_t& value) {
16018 thread_local static __as_enum__<new_type_t, current_type_t, typename std::conditional<std::is_enum<current_type_t>::value, std::true_type, std::false_type>
::type>
e;
16019 return e.convert(value);
16036 template<
typename new_type_t,
typename current_type_t>
16037 new_type_t&
as(current_type_t& value) {
16038 thread_local static __as_enum__<new_type_t, current_type_t, typename std::conditional<std::is_enum<current_type_t>::value, std::true_type, std::false_type>
::type>
e;
16039 return e.convert(value);
16055 template<
typename new_type_t,
typename current_type_t>
16056 const new_type_t*
as(
const current_type_t* value) {
16057 return xtd::convert_pointer::to_ptr<new_type_t>(value);
16073 template<
typename new_type_t,
typename current_type_t>
16074 new_type_t*
as(current_type_t* value) {
16075 return xtd::convert_pointer::to_ptr<new_type_t>(value);
16092 template<
typename new_type_t,
typename current_type_t>
16093 std::unique_ptr<new_type_t>
as(std::unique_ptr<current_type_t>& value) {
16094 return xtd::convert_pointer::to_unique_ptr<new_type_t>(value);
16110 template<
typename new_type_t,
typename current_type_t>
16111 std::unique_ptr<new_type_t>
as(std::unique_ptr<current_type_t>&& value) {
16112 return xtd::convert_pointer::to_unique_ptr<new_type_t>(value);
16129 template<
typename new_type_t,
typename current_type_t>
16130 std::shared_ptr<new_type_t>
as(
const std::shared_ptr<current_type_t>& value) {
16131 return xtd::convert_pointer::to_shared_ptr<new_type_t>(value);
16147 template<
typename new_type_t,
typename current_type_t>
16148 std::shared_ptr<new_type_t>
as(std::shared_ptr<current_type_t>& value) {
16149 return xtd::convert_pointer::to_shared_ptr<new_type_t>(value);
16166 template<
typename new_type_t,
typename current_type_t>
16167 std::shared_ptr<new_type_t>
as(std::shared_ptr<current_type_t>&& value) {
16168 return xtd::convert_pointer::to_shared_ptr<new_type_t>(value);
16236#if defined(__cpp_lib_char8_t)
16418#if defined(__cpp_lib_char8_t)
16528#if defined(__cpp_lib_char8_t)
16674#if defined(__cpp_lib_char8_t)
16820#if defined(__cpp_lib_char8_t)
17038#if defined(__cpp_lib_char8_t)
17328#if defined(__cpp_lib_char8_t)
17510#if defined(__cpp_lib_char8_t)
17620#if defined(__cpp_lib_char8_t)
17766#if defined(__cpp_lib_char8_t)
17948#if defined(__cpp_lib_char8_t)
18058#if defined(__cpp_lib_char8_t)
18204#if defined(__cpp_lib_char8_t)
18386#if defined(__cpp_lib_char8_t)
18496#if defined(__cpp_lib_char8_t)
18571template<
typename new_type_t,
typename current_type_t>
18572new_type_t* __convert_value__(current_type_t* value) {
18573 return xtd::as<new_type_t>(value);
Contains std::any type and std::bad_any_cast exception.
static std::u32string to_u32string(const std::string &str) noexcept
Converts std::string to std::u32string.
static std::u8string to_u8string(const std::string &str) noexcept
Converts std::string to std::u8string.
static xtd::ustring to_ustring(const std::string &str) noexcept
Converts std::string to xtd::ustring.
static const std::string & to_string(const std::string &str) noexcept
Converts std::string to std::string.
static std::u16string to_u16string(const std::string &str) noexcept
Converts std::string to std::u16string.
static std::wstring to_wstring(const std::string &str) noexcept
Converts std::string to std::wstring.
static double to_double(std::any value)
Convert std::any to double.
static wchar to_wchar(std::any value)
Convert std::any to wchar.
static ustring to_string(std::any value)
Convert std::any to ustring.
static bool to_boolean(std::any value)
Convert std::any to bool.
static float to_single(std::any value)
Convert std::any to single.
static xtd::ulong to_ullong(std::any value)
Convert std::any to xtd::ulong.
static int32 to_int32(std::any value)
Convert std::any to int32.
static int64 to_int64(std::any value)
Convert std::any to int64.
static char8 to_char8(std::any value)
Convert std::any to char8.
static uint16 to_uint16(std::any value)
Convert std::any to uint16.
static char32 to_char32(std::any value)
Convert std::any to char32.
static decimal to_decimal(std::any value)
Convert std::any to decimal.
static int16 to_int16(std::any value)
Convert std::any to int16.
static char16 to_char16(std::any value)
Convert std::any to char16.
static slong to_llong(std::any value)
Convert std::any to slong.
static uint64 to_uint64(std::any value)
Convert std::any to uint64.
static xtd::byte to_byte(std::any value)
Convert std::any to byte.
static uint32 to_uint32(std::any value)
Convert std::any to uint32.
static char to_char(std::any value)
Convert std::any to char.
static sbyte to_sbyte(std::any value)
Convert std::any to sbyte.
The exception that is thrown for invalid casting or explicit conversion.
Definition invalid_cast_exception.h:18
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
Contains xtd::convert class.
Contains xtd::convert class.
Contains xtd::convert_string class.
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
char8_t char8
Represents a 8-bit unicode character.
Definition types.h:64
wchar_t wchar
Represents a wide character.
Definition types.h:286
int_least16_t int16
Represents a 16-bit signed integer.
Definition types.h:120
long double decimal
Represents a decimal-precision floating-point number.
Definition types.h:98
__ulong__ ulong
Represents a 32-bit or 64-bit unsigned integer.
Definition types.h:274
char16_t char16
Represents a 16-bit unicode character.
Definition types.h:76
int_least8_t sbyte
Represents a 8-bit signed integer.
Definition types.h:175
int_least64_t int64
Represents a 64-bit signed integer.
Definition types.h:142
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition types.h:230
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
char32_t char32
Represents a 32-bit unicode character.
Definition types.h:87
uint_least64_t uint64
Represents a 64-bit unsigned integer.
Definition types.h:252
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition types.h:241
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition types.h:208
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition types.h:41
std::type_info type
Stores information about a type.
Definition types.h:219
float as< float >(std::any value)
Casts a type into another type.
Definition as.h:7710
std::u32string as< std::u32string >(const std::string &value)
Casts a type into another type.
Definition as.h:16324
new_type_t as(std::any value)
Casts a type into another type.
Definition as.h:37
char8 as< char8 >(std::any value)
Casts a type into another type.
Definition as.h:3227
slong as< slong >(std::any value)
Casts a type into another type.
Definition as.h:10768
std::wstring as< std::wstring >(const std::string &value)
Casts a type into another type.
Definition as.h:16360
xtd::ustring as< xtd::ustring >(const std::string &value)
Casts a type into another type.
Definition as.h:16214
char16 as< char16 >(std::any value)
Casts a type into another type.
Definition as.h:3970
std::string as< std::string >(const std::string &value)
Casts a type into another type.
Definition as.h:16188
std::u16string as< std::u16string >(const std::string &value)
Casts a type into another type.
Definition as.h:16288
int16 as< int16 >(std::any value)
Casts a type into another type.
Definition as.h:8458
int32 as< int32 >(std::any value)
Casts a type into another type.
Definition as.h:9228
uint32 as< uint32 >(std::any value)
Casts a type into another type.
Definition as.h:13078
wchar as< wchar >(std::any value)
Casts a type into another type.
Definition as.h:5466
uint64 as< uint64 >(std::any value)
Casts a type into another type.
Definition as.h:13848
xtd::ulong as< xtd::ulong >(std::any value)
Casts a type into another type.
Definition as.h:14618
sbyte as< sbyte >(std::any value)
Casts a type into another type.
Definition as.h:11538
xtd::byte as< xtd::byte >(std::any value)
Casts a type into another type.
Definition as.h:1708
std::u8string as< std::u8string >(const std::string &value)
Casts a type into another type.
Definition as.h:16251
ustring as< ustring >(std::any value)
Casts a type into another type.
Definition as.h:15388
double as< double >(std::any value)
Casts a type into another type.
Definition as.h:6962
char32 as< char32 >(std::any value)
Casts a type into another type.
Definition as.h:4718
decimal as< decimal >(std::any value)
Casts a type into another type.
Definition as.h:6214
char as< char >(std::any value)
Casts a type into another type.
Definition as.h:2478
uint16 as< uint16 >(std::any value)
Casts a type into another type.
Definition as.h:12308
int64 as< int64 >(std::any value)
Casts a type into another type.
Definition as.h:9998
bool as< bool >(std::any value)
Casts a type into another type.
Definition as.h:960
Contains xtd::invalid_cast_exception exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd fundamental types.