Types in xtd
- By design xtd has defined its own types which are only ever aliases to the fixed integer types of c++.
- You are not obliged to use the xtd types, you are even encouraged to use the standard types or those you want.
- The xtd defines
unboxed
andboxed
types listed below. Theunboxed
types is same as the native type. Theboxed
type is an xtd::box inherited from xtd::object.
Remarks
For more performance prefere used unboxed
type. Used boxed
type when necessary, e.g., to parse, polymorphism, ...
Types list
Unboxed type | Boxed type | C++11 type | C++ standard type | Size in bytes | Value |
---|---|---|---|---|---|
xtd::boolean | xtd::boolean_object | bool | bool | 1 | Represents a boolean value. |
char | xtd::char_object | char | char | 1 | Represents a characters. |
xtd::char8 | xtd::char8_object | char8_t | char | 1 | Represents a unicode characters. |
xtd::char16 | xtd::char16_object | char16_t | short | 2 | Represents a unicode characters. |
xtd::char32 | xtd::char32_object | char32_t | int | 4 | Represents a unicode characters. |
xtd::wchar | xtd::wchar_object | wchar_t | short - or - int (1) | 2 - or - 4 (1) | Represents a unicode characters. |
xtd::byte | xtd::byte_object | uint_least8_t | unsigned char | 1 | Represents a 8-bit unsigned integer. |
xtd::int16 | xtd::int16_object | int_least16_t | short | 2 | Represents a 16-bit signed integer. |
xtd::int32 | xtd::int32_object | int_least32_t | int | 4 | Represents a 32-bit signed integer. |
xtd::int64 | xtd::int64_object | int_least64_t | long long. | 8 | Represents a 64-bit signed integer. |
xtd::intptr | xtd::intptr_object | intmax_t | int - or - long long (2) | 4 - or - 8 (2) | Represent a pointer or a handle. |
xtd::sbyte | xtd::sbyte_object | int_least8_t | char | 1 | Represents a 8-bit signed integer. |
xtd::uint16 | xtd::uint16_object | uint_least16_t | unsigned short | 2 | Represents a 16-bit unsigned integer. |
xtd::uint32 | xtd::uint32_object | uint_least32_t | unsigned int | 4 | Represents a 32-bit unsigned integer. |
xtd::uint64 | xtd::uint64_object | uint_least64_t | unsigned long long | 8 | Represents a 64-bit unsigned integer. |
xtd::uintptr | xtd::uintptr_object | uintmax_t | unsigned int - or - unsigned long long (2) | 4 - or - 8 (2) | Represent an unsigned pointer or a handle. |
xtd::single | xtd::single_object | float | float | 4 | Represents a single-precision floating-point number. |
double | xtd::double_object | double | double | 8 | Represents a double-precision floating-point number. |
xtd::decimal (3) | xtd::decimal_object | long double (3) | long double (3) | 8 - or -16 (3) | Represents a double-precision floating-point number. |
xtd::size | xtd::size_object | size_t | result of the sizeof operator (2) | 4 - or - 8 (2) | Represent an unsigned pointer or a handle. |
xtd::date_time | xtd::date_time | / | / | 8 | Represents an instant in time, typically expressed as a date and time of day. |
const char* | xtd::ustring | std::string | std::string (4) | variable | Represents text as a series of unicode characters. |
(1) Depend of OS : if build on Windows is 2 bytes, if build on Linux or many other non-Windows systems is 4 bytes.
(2) Depend of build : if build in 32 bits the size is 4 bytes, if build in 64 bits the size is 8 bytes.
(3) xtd::decimal is an extended precision floating-point type. Matches IEEE-754 binary128 format if supported, otherwise matches IEEE-754 binary64-extended format if supported, otherwise matches some non-IEEE-754 extended floating-point format as long as its precision is better than binary64 and range is at least as good as binary64, otherwise matches IEEE-754 binary64 format.
- binary128 format is used by some HP-UX, SPARC, MIPS, ARM64, and z/OS implementations.
- The most well known IEEE-754 binary64-extended format is 80-bit x87 extended precision format. It is used by many x86 and x86-64 implementations (a notable exception is MSVC, which implements
long double
in the same format asdouble
, i.e. binary64).
(4) The std::string type is the main string datatype in standard C++ since 1998, but it was not always part of C++98.
For more information about c++ type see cppreference language type section.
For the complete list of xtd types see xtd - Referecne Guide - types section.
Limits
xtd define the minimum and maximum constant value for each types.
Remarks
Of course, std::numeric_limits works for the types described above except for xtd::date_time.
Boxing
For explicit boxing a type into corresponding object class use xtd::boxing method. By default, the boxing implicit in the corresponding object is used.
bool value_unboxed = true;
xtd::boolean_object value_boxed1 = value_unboxed; // implicit
xtd::boolean_object value_boxed2 = xtd::boxing(value_unboxed); // explicit
auto ready_boxed3 = xtd::boxing(value_unboxed); // explicit with auto is xtd::boolean_object type
Unboxing
For explicit unboxing a object class into corresponding type use xtd::unboxing method. By default, the unboxing implicit in the corresponding type is used.
xtd::boolean_object value_boxed = true;
bool value_unboxed1 = value_boxed; // implicit
bool value_unboxed2 = xtd::unboxing(value_boxed); // explict
auto value_unboxed3 = xtd::unboxing(value_boxed); // explict with auto is bool
See also