31 template<
typename new_type_t>
32 new_type_t
as(std::any value) {
34 return any_cast<new_type_t>(value);
35 }
catch (
const std::exception&
e) {
53 template<
typename new_type_t>
54 new_type_t
as(
bool value) {
55 return static_cast<new_type_t
>(value);
71 template<
typename new_type_t>
72 new_type_t
as(byte_t value) {
73 return static_cast<new_type_t
>(value);
89 template<
typename new_type_t>
90 new_type_t
as(
char value) {
91 return static_cast<new_type_t
>(value);
107 template<
typename new_type_t>
108 new_type_t
as(
char8_t value) {
109 return static_cast<new_type_t
>(value);
125 template<
typename new_type_t>
126 new_type_t
as(
char16_t value) {
127 return static_cast<new_type_t
>(value);
143 template<
typename new_type_t>
144 new_type_t
as(
char32_t value) {
145 return static_cast<new_type_t
>(value);
161 template<
typename new_type_t>
162 new_type_t
as(
wchar_t value) {
163 return static_cast<new_type_t
>(value);
179 template<
typename new_type_t>
180 new_type_t
as(decimal_t value) {
181 return static_cast<new_type_t
>(value);
197 template<
typename new_type_t>
198 new_type_t
as(
double value) {
199 return static_cast<new_type_t
>(value);
215 template<
typename new_type_t>
216 new_type_t
as(
float value) {
217 return static_cast<new_type_t
>(value);
233 template<
typename new_type_t>
234 new_type_t
as(int16_t value) {
235 return static_cast<new_type_t
>(value);
251 template<
typename new_type_t>
252 new_type_t
as(int32_t value) {
253 return static_cast<new_type_t
>(value);
269 template<
typename new_type_t>
270 new_type_t
as(int64_t value) {
271 return static_cast<new_type_t
>(value);
287 template<
typename new_type_t>
288 new_type_t
as(llong_t value) {
289 return static_cast<new_type_t
>(value);
305 template<
typename new_type_t>
306 new_type_t
as(sbyte_t value) {
307 return static_cast<new_type_t
>(value);
323 template<
typename new_type_t>
324 new_type_t
as(uint16_t value) {
325 return static_cast<new_type_t
>(value);
341 template<
typename new_type_t>
342 new_type_t
as(uint32_t value) {
343 return static_cast<new_type_t
>(value);
359 template<
typename new_type_t>
360 new_type_t
as(uint64_t value) {
361 return static_cast<new_type_t
>(value);
377 template<
typename new_type_t>
378 new_type_t
as(ullong_t value) {
379 return static_cast<new_type_t
>(value);
396 template<
typename new_type_t>
399 return dynamic_cast<const new_type_t&
>(value);
400 }
catch (
const std::exception&
e) {
403 throw std::bad_cast();
420 template<
typename new_type_t>
423 return dynamic_cast<new_type_t&
>(value);
424 }
catch (
const std::exception&
e) {
427 throw std::bad_cast();
431 template<
typename new_type_t>
433 throw invalid_cast_exception(
csf_);
435 template<
typename new_type_t>
436 new_type_t
as(byte_t value, byte_t from_base) {
437 throw invalid_cast_exception(
csf_);
439 template<
typename new_type_t>
440 new_type_t
as(int16_t value, byte_t from_base) {
441 throw invalid_cast_exception(
csf_);
443 template<
typename new_type_t>
444 new_type_t
as(int32_t value, byte_t from_base) {
445 throw invalid_cast_exception(
csf_);
447 template<
typename new_type_t>
448 new_type_t
as(int64_t value, byte_t from_base) {
449 throw invalid_cast_exception(
csf_);
451 template<
typename new_type_t>
452 new_type_t
as(llong_t value, byte_t from_base) {
453 throw invalid_cast_exception(
csf_);
455 template<
typename new_type_t>
456 new_type_t
as(sbyte_t value, byte_t from_base) {
457 throw invalid_cast_exception(
csf_);
459 template<
typename new_type_t>
460 new_type_t
as(uint16_t value, byte_t from_base) {
461 throw invalid_cast_exception(
csf_);
463 template<
typename new_type_t>
464 new_type_t
as(uint32_t value, byte_t from_base) {
465 throw invalid_cast_exception(
csf_);
467 template<
typename new_type_t>
468 new_type_t
as(uint64_t value, byte_t from_base) {
469 throw invalid_cast_exception(
csf_);
471 template<
typename new_type_t>
472 new_type_t
as(ullong_t value, byte_t from_base) {
473 throw invalid_cast_exception(
csf_);
486 template<
typename new_type_t>
487 new_type_t
as(
const std::string& value) {
489 return dynamic_cast<const new_type_t&
>(value);
490 }
catch (
const std::exception&
e) {
493 throw std::bad_cast();
505 template<
typename new_type_t>
506 new_type_t
as(std::string& value) {
508 return dynamic_cast<new_type_t&
>(value);
509 }
catch (
const std::exception&
e) {
512 throw std::bad_cast();
524 template<
typename new_type_t>
525 new_type_t
as(
const std::u8string& value) {
527 return dynamic_cast<const new_type_t&
>(value);
528 }
catch (
const std::exception&
e) {
531 throw std::bad_cast();
543 template<
typename new_type_t>
544 new_type_t
as(std::u8string& value) {
546 return dynamic_cast<new_type_t&
>(value);
547 }
catch (
const std::exception&
e) {
550 throw std::bad_cast();
562 template<
typename new_type_t>
563 new_type_t
as(
const std::u16string& value) {
565 return dynamic_cast<const new_type_t&
>(value);
566 }
catch (
const std::exception&
e) {
569 throw std::bad_cast();
581 template<
typename new_type_t>
582 new_type_t
as(std::u16string& value) {
584 return dynamic_cast<new_type_t&
>(value);
585 }
catch (
const std::exception&
e) {
588 throw std::bad_cast();
600 template<
typename new_type_t>
601 new_type_t
as(
const std::u32string& value) {
603 return dynamic_cast<const new_type_t&
>(value);
604 }
catch (
const std::exception&
e) {
607 throw std::bad_cast();
619 template<
typename new_type_t>
620 new_type_t
as(std::u32string& value) {
622 return dynamic_cast<new_type_t&
>(value);
623 }
catch (
const std::exception&
e) {
626 throw std::bad_cast();
638 template<
typename new_type_t>
639 new_type_t
as(
const std::wstring& value) {
641 return dynamic_cast<const new_type_t&
>(value);
642 }
catch (
const std::exception&
e) {
645 throw std::bad_cast();
657 template<
typename new_type_t>
658 new_type_t
as(std::wstring& value) {
660 return dynamic_cast<new_type_t&
>(value);
661 }
catch (
const std::exception&
e) {
664 throw std::bad_cast();
680 template<
typename new_type_t>
681 new_type_t
as(
const char* value) {
682 return reinterpret_cast<new_type_t
>(value);
698 template<
typename new_type_t>
699 new_type_t
as(
char* value) {
700 return reinterpret_cast<new_type_t
>(value);
716 template<
typename new_type_t>
717 new_type_t
as(
const char8_t* value) {
718 return reinterpret_cast<new_type_t
>(value);
734 template<
typename new_type_t>
735 new_type_t
as(
char8_t* value) {
736 return reinterpret_cast<new_type_t
>(value);
752 template<
typename new_type_t>
753 new_type_t
as(
const char16_t* value) {
754 return reinterpret_cast<new_type_t
>(value);
770 template<
typename new_type_t>
771 new_type_t
as(
char16_t* value) {
772 return reinterpret_cast<new_type_t
>(value);
788 template<
typename new_type_t>
789 new_type_t
as(
const char32_t* value) {
790 return reinterpret_cast<new_type_t
>(value);
806 template<
typename new_type_t>
807 new_type_t
as(
char32_t* value) {
808 return reinterpret_cast<new_type_t
>(value);
824 template<
typename new_type_t>
825 new_type_t
as(
const wchar_t* value) {
826 return reinterpret_cast<new_type_t
>(value);
842 template<
typename new_type_t>
843 new_type_t
as(
wchar_t* value) {
844 return reinterpret_cast<new_type_t
>(value);
14361 template<
typename new_type_t,
typename current_type_t>
14362 const new_type_t&
as(
const current_type_t& value) {
14363 return xtd::convert_pointer::to_ref<new_type_t>(value);
14378 template<
typename new_type_t,
typename current_type_t>
14379 new_type_t&
as(current_type_t& value) {
14380 return xtd::convert_pointer::to_ref<new_type_t>(value);
14394 template<
typename new_type_t,
typename current_type_t>
14395 const new_type_t*
as(
const current_type_t* value) {
14396 return xtd::convert_pointer::to_ptr<new_type_t>(value);
14410 template<
typename new_type_t,
typename current_type_t>
14411 new_type_t*
as(current_type_t* value) {
14412 return xtd::convert_pointer::to_ptr<new_type_t>(value);
14427 template<
typename new_type_t,
typename current_type_t>
14428 std::unique_ptr<new_type_t>
as(std::unique_ptr<current_type_t>& value) {
14429 return xtd::convert_pointer::to_unique_ptr<new_type_t>(value);
14443 template<
typename new_type_t,
typename current_type_t>
14444 std::unique_ptr<new_type_t>
as(std::unique_ptr<current_type_t>&& value) {
14445 return xtd::convert_pointer::to_unique_ptr<new_type_t>(value);
14460 template<
typename new_type_t,
typename current_type_t>
14461 std::shared_ptr<new_type_t>
as(
const std::shared_ptr<current_type_t>& value) {
14462 return xtd::convert_pointer::to_shared_ptr<new_type_t>(value);
14476 template<
typename new_type_t,
typename current_type_t>
14477 std::shared_ptr<new_type_t>
as(std::shared_ptr<current_type_t>& value) {
14478 return xtd::convert_pointer::to_shared_ptr<new_type_t>(value);
14493 template<
typename new_type_t,
typename current_type_t>
14494 std::shared_ptr<new_type_t>
as(std::shared_ptr<current_type_t>&& value) {
14495 return xtd::convert_pointer::to_shared_ptr<new_type_t>(value);
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 char16_t to_char16(std::any value)
Convert std::any to char16.
static ustring to_string(std::any value)
Convert std::any to ustring.
static int64_t to_int64(std::any value)
Convert std::any to int64.
static bool to_boolean(std::any value)
Convert std::any to bool.
static byte_t to_byte(std::any value)
Convert std::any to byte.
static char8_t to_char8(std::any value)
Convert std::any to char8.
static float to_single(std::any value)
Convert std::any to single.
static sbyte_t to_sbyte(std::any value)
Convert std::any to sbyte.
static int16_t to_int16(std::any value)
Convert std::any to int16.
static ullong_t to_ullong(type_t value) noexcept
Convert type_t to ullong.
Definition: convert.h:4731
static uint32_t to_uint32(std::any value)
Convert std::any to uint32.
static uint64_t to_uint64(std::any value)
Convert std::any to uint64.
static int32_t to_int32(std::any value)
Convert std::any to int32.
static wchar_t to_wchar(std::any value)
Convert std::any to wchar.
static char32_t to_char32(std::any value)
Convert std::any to char32.
static decimal_t to_decimal(std::any value)
Convert std::any to decimal.
static char to_char(std::any value)
Convert std::any to char.
static uint16_t to_uint16(std::any value)
Convert std::any to uint16.
static llong_t to_llong(std::any value)
Convert std::any to llong.
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:48
Contains xtd::convert class.
Contains xtd::convert class.
Contains xtd::convert_string class.
#define csf_
Provides information about the current stack frame.
Definition: stack_frame.h:213
float as< float >(std::any value)
Casts a type into another type.
Definition: as.h:6915
std::u32string as< std::u32string >(const std::string &value)
Casts a type into another type.
Definition: as.h:14633
char16_t as< char16_t >(std::any value)
Casts a type into another type.
Definition: as.h:3565
new_type_t as(std::any value)
Casts a type into another type.
Definition: as.h:32
int16_t as< int16_t >(std::any value)
Casts a type into another type.
Definition: as.h:7585
uint64_t as< uint64_t >(std::any value)
Casts a type into another type.
Definition: as.h:12415
byte_t as< byte_t >(std::any value)
Casts a type into another type.
Definition: as.h:1535
wchar_t as< wchar_t >(std::any value)
Casts a type into another type.
Definition: as.h:4905
char32_t as< char32_t >(std::any value)
Casts a type into another type.
Definition: as.h:4235
int64_t as< int64_t >(std::any value)
Casts a type into another type.
Definition: as.h:8965
std::wstring as< std::wstring >(const std::string &value)
Casts a type into another type.
Definition: as.h:14665
xtd::ustring as< xtd::ustring >(const std::string &value)
Casts a type into another type.
Definition: as.h:14537
std::string as< std::string >(const std::string &value)
Casts a type into another type.
Definition: as.h:14513
char8_t as< char8_t >(std::any value)
Casts a type into another type.
Definition: as.h:2895
std::u16string as< std::u16string >(const std::string &value)
Casts a type into another type.
Definition: as.h:14601
llong_t as< llong_t >(std::any value)
Casts a type into another type.
Definition: as.h:9655
std::u8string as< std::u8string >(const std::string &value)
Casts a type into another type.
Definition: as.h:14569
ustring as< ustring >(std::any value)
Casts a type into another type.
Definition: as.h:13795
ullong_t as< ullong_t >(std::any value)
Casts a type into another type.
Definition: as.h:13105
uint32_t as< uint32_t >(std::any value)
Casts a type into another type.
Definition: as.h:11725
double as< double >(std::any value)
Casts a type into another type.
Definition: as.h:6245
sbyte_t as< sbyte_t >(std::any value)
Casts a type into another type.
Definition: as.h:10345
char as< char >(std::any value)
Casts a type into another type.
Definition: as.h:2225
decimal_t as< decimal_t >(std::any value)
Casts a type into another type.
Definition: as.h:5575
int32_t as< int32_t >(std::any value)
Casts a type into another type.
Definition: as.h:8275
uint16_t as< uint16_t >(std::any value)
Casts a type into another type.
Definition: as.h:11035
bool as< bool >(std::any value)
Casts a type into another type.
Definition: as.h:865
Contains xtd::invalid_cast_exception exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd fundamental types.