xtd 0.2.0
__as_generic.hpp
Go to the documentation of this file.
1
3#pragma once
4
6#if !defined(__XTD_CORE_INTERNAL__)
7#error "Do not include this file: Internal use only"
8#endif
10
11#define __XTD_STD_INTERNAL__
12#include "__xtd_std_version.hpp"
13#undef __XTD_STD_INTERNAL__
14
16namespace xtd {
35 template<class new_type_t>
36 new_type_t as(xtd::any value) {
37 try {
38 return xtd::any_cast<new_type_t>(value);
39 } catch (const std::exception& e) {
41 }
42 }
43
61 template<class new_type_t>
62 new_type_t as(bool value) {
63 return static_cast<new_type_t>(value);
64 }
65
83 template<class new_type_t>
84 new_type_t as(xtd::byte value) {
85 return static_cast<new_type_t>(value);
86 }
87
105 template<class new_type_t>
106 new_type_t as(char value) {
107 return static_cast<new_type_t>(value);
108 }
109
127 template<class new_type_t>
128 new_type_t as(char8 value) {
129 return static_cast<new_type_t>(value);
130 }
131
149 template<class new_type_t>
150 new_type_t as(char16 value) {
151 return static_cast<new_type_t>(value);
152 }
153
171 template<class new_type_t>
172 new_type_t as(char32 value) {
173 return static_cast<new_type_t>(value);
174 }
175
193 template<class new_type_t>
194 new_type_t as(wchar value) {
195 return static_cast<new_type_t>(value);
196 }
197
215 template<class new_type_t>
216 new_type_t as(decimal value) {
217 return static_cast<new_type_t>(value);
218 }
219
237 template<class new_type_t>
238 new_type_t as(double value) {
239 return static_cast<new_type_t>(value);
240 }
241
259 template<class new_type_t>
260 new_type_t as(float value) {
261 return static_cast<new_type_t>(value);
262 }
263
281 template<class new_type_t>
282 new_type_t as(int16 value) {
283 return static_cast<new_type_t>(value);
284 }
285
303 template<class new_type_t>
304 new_type_t as(int32 value) {
305 return static_cast<new_type_t>(value);
306 }
307
325 template<class new_type_t>
326 new_type_t as(int64 value) {
327 return static_cast<new_type_t>(value);
328 }
329
347 template<class new_type_t>
348 new_type_t as(slong value) {
349 return static_cast<new_type_t>(value);
350 }
351
369 template<class new_type_t>
370 new_type_t as(sbyte value) {
371 return static_cast<new_type_t>(value);
372 }
373
391 template<class new_type_t>
392 new_type_t as(uint16 value) {
393 return static_cast<new_type_t>(value);
394 }
395
413 template<class new_type_t>
414 new_type_t as(uint32 value) {
415 return static_cast<new_type_t>(value);
416 }
417
435 template<class new_type_t>
436 new_type_t as(uint64 value) {
437 return static_cast<new_type_t>(value);
438 }
439
457 template<class new_type_t>
458 new_type_t as(xtd::ulong value) {
459 return static_cast<new_type_t>(value);
460 }
461
480 template<class new_type_t>
481 new_type_t as(const xtd::string& value) {
482 try {
483 return dynamic_cast<const new_type_t&>(value);
484 } catch (const std::exception& e) {
486 }
488 }
489
508 template<class new_type_t>
509 new_type_t as(xtd::string& value) {
510 try {
511 return dynamic_cast<new_type_t&>(value);
512 } catch (const std::exception& e) {
514 }
516 }
517
519 template<class new_type_t>
520 new_type_t as(const xtd::string& value, xtd::byte from_base) {
522 }
523 template<class new_type_t>
524 new_type_t as(xtd::byte value, xtd::byte from_base) {
526 }
527 template<class new_type_t>
528 new_type_t as(int16 value, xtd::byte from_base) {
530 }
531 template<class new_type_t>
532 new_type_t as(int32 value, xtd::byte from_base) {
534 }
535 template<class new_type_t>
536 new_type_t as(int64 value, xtd::byte from_base) {
538 }
539 template<class new_type_t>
540 new_type_t as(slong value, xtd::byte from_base) {
542 }
543 template<class new_type_t>
544 new_type_t as(sbyte value, xtd::byte from_base) {
546 }
547 template<class new_type_t>
548 new_type_t as(uint16 value, xtd::byte from_base) {
550 }
551 template<class new_type_t>
552 new_type_t as(uint32 value, xtd::byte from_base) {
554 }
555 template<class new_type_t>
556 new_type_t as(uint64 value, xtd::byte from_base) {
558 }
559 template<class new_type_t>
560 new_type_t as(xtd::ulong value, xtd::byte from_base) {
562 }
564
578 template<class new_type_t>
579 new_type_t as(const std::string& value) {
580 try {
581 return dynamic_cast<const new_type_t&>(value);
582 } catch (const std::exception& e) {
584 }
586 }
587
601 template<class new_type_t>
602 new_type_t as(std::string& value) {
603 try {
604 return dynamic_cast<new_type_t&>(value);
605 } catch (const std::exception& e) {
607 }
609 }
610
624 template<class new_type_t>
625 new_type_t as(const std::u8string& value) {
626 try {
627 return dynamic_cast<const new_type_t&>(value);
628 } catch (const std::exception& e) {
630 }
632 }
633
647 template<class new_type_t>
648 new_type_t as(std::u8string& value) {
649 try {
650 return dynamic_cast<new_type_t&>(value);
651 } catch (const std::exception& e) {
653 }
655 }
656
670 template<class new_type_t>
671 new_type_t as(const std::u16string& value) {
672 try {
673 return dynamic_cast<const new_type_t&>(value);
674 } catch (const std::exception& e) {
676 }
678 }
679
693 template<class new_type_t>
694 new_type_t as(std::u16string& value) {
695 try {
696 return dynamic_cast<new_type_t&>(value);
697 } catch (const std::exception& e) {
699 }
701 }
702
716 template<class new_type_t>
717 new_type_t as(const std::u32string& value) {
718 try {
719 return dynamic_cast<const new_type_t&>(value);
720 } catch (const std::exception& e) {
722 }
724 }
725
739 template<class new_type_t>
740 new_type_t as(std::u32string& value) {
741 try {
742 return dynamic_cast<new_type_t&>(value);
743 } catch (const std::exception& e) {
745 }
747 }
748
762 template<class new_type_t>
763 new_type_t as(const std::wstring& value) {
764 try {
765 return dynamic_cast<const new_type_t&>(value);
766 } catch (const std::exception& e) {
768 }
770 }
771
785 template<class new_type_t>
786 new_type_t as(std::wstring& value) {
787 try {
788 return dynamic_cast<new_type_t&>(value);
789 } catch (const std::exception& e) {
791 }
793 }
794
812 template<class new_type_t>
813 new_type_t as(const char* value) {
814 return reinterpret_cast<new_type_t>(value);
815 }
816
834 template<class new_type_t>
835 new_type_t as(char* value) {
836 return reinterpret_cast<new_type_t>(value);
837 }
838
856 template<class new_type_t>
857 new_type_t as(const char8* value) {
858 return reinterpret_cast<new_type_t>(value);
859 }
860
878 template<class new_type_t>
879 new_type_t as(char8* value) {
880 return reinterpret_cast<new_type_t>(value);
881 }
882
900 template<class new_type_t>
901 new_type_t as(const char16* value) {
902 return reinterpret_cast<new_type_t>(value);
903 }
904
922 template<class new_type_t>
923 new_type_t as(char16* value) {
924 return reinterpret_cast<new_type_t>(value);
925 }
926
944 template<class new_type_t>
945 new_type_t as(const char32* value) {
946 return reinterpret_cast<new_type_t>(value);
947 }
948
966 template<class new_type_t>
967 new_type_t as(char32* value) {
968 return reinterpret_cast<new_type_t>(value);
969 }
970
988 template<class new_type_t>
989 new_type_t as(const wchar* value) {
990 return reinterpret_cast<new_type_t>(value);
991 }
992
1010 template<class new_type_t>
1011 new_type_t as(wchar* value) {
1012 return reinterpret_cast<new_type_t>(value);
1013 }
1014}
Contains __xtd_std_version definitions.
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
@ invalid_cast
The cast is not valid.
Definition exception_case.hpp:61
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition slong.hpp:27
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
__ulong__ ulong
Represents a 32-bit or 64-bit unsigned integer.
Definition ulong.hpp:27
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:23
std::any any
Represents the any alias on std::any.
Definition any.hpp:24
type_t any_cast(const xtd::any &operand)
Performs type-safe access to the contained object.
Definition any_cast.hpp:22
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ e
The E key.
Definition console_key.hpp:96
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8