6#define __XTD_CORE_INTERNAL__
18#undef __XTD_CORE_INTERNAL__
19#define __XTD_STD_INTERNAL__
21#undef __XTD_STD_INTERNAL__
40 template<
typename value_t>
41 inline std::string
to_string(
const value_t& value,
const std::string& fmt,
const std::locale& loc) {
return __to_string_polymorphic(value, fmt, loc, std::is_polymorphic<value_t>());}
54 inline std::string
to_string(
const bool& value,
const std::string& fmt,
const std::locale& loc) {
return __boolean_formatter(fmt, value, loc);}
67 inline std::string
to_string(
const sbyte& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
80 inline std::string
to_string(
const char& value,
const std::string& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
93 inline std::string
to_string(
const unsigned char& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
106 inline std::string
to_string(
const short& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
119 inline std::string
to_string(
const unsigned short& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
132 inline std::string
to_string(
const int& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
145 inline std::string
to_string(
const unsigned int& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
158 inline std::string
to_string(
const long& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
171 inline std::string
to_string(
const unsigned long& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
184 inline std::string
to_string(
const long long& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
197 inline std::string
to_string(
const unsigned long long& value,
const std::string& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
210 inline std::string
to_string(
const float& value,
const std::string& fmt,
const std::locale& loc) {
return __floating_point_formatter(fmt, value, loc);}
223 inline std::string
to_string(
const double& value,
const std::string& fmt,
const std::locale& loc) {
return __floating_point_formatter(fmt, value, loc);}
236 inline std::string
to_string(
const long double& value,
const std::string& fmt,
const std::locale& loc) {
return __floating_point_formatter(fmt, value, loc);}
249 inline std::string
to_string(
const std::chrono::system_clock::time_point& value,
const std::string& fmt,
const std::locale& loc) {
return __date_time_formatter(fmt, std::chrono::system_clock::to_time_t(value), std::chrono::duration_cast<std::chrono::nanoseconds>(value.time_since_epoch()).count() % 1000000000, loc);}
262 inline std::string
to_string(
const std::tm& value,
const std::string& fmt,
const std::locale& loc) {
return __date_time_formatter(fmt, value, 0, loc);}
274 template<
typename type_t,
typename Period>
275 inline std::string
to_string(
const std::chrono::duration<type_t, Period>& value,
const std::string& fmt,
const std::locale& loc) {
return __duration_formatter(fmt, value, loc);}
277#if defined(__xtd__cpp_lib_char8_t)
289 inline std::string
to_string(
const char8& value,
const std::string& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
303 inline std::string
to_string(
const char16& value,
const std::string& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
316 inline std::string
to_string(
const char32& value,
const std::string& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
329 inline std::string
to_string(
const wchar& value,
const std::string& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
332 std::string
to_string(
const char* value,
const std::string& fmt,
const std::locale& loc);
333#if defined(__xtd__cpp_lib_char8_t)
334 std::string
to_string(
const char8* value,
const std::string& fmt,
const std::locale& loc);
336 std::string
to_string(
const char16* value,
const std::string& fmt,
const std::locale& loc);
337 std::string
to_string(
const char32* value,
const std::string& fmt,
const std::locale& loc);
338 std::string
to_string(
const wchar* value,
const std::string& fmt,
const std::locale& loc);
339 std::string
to_string(
const std::string& value,
const std::string& fmt,
const std::locale& loc);
340 std::string
to_string(
const xtd::string& value,
const std::string& fmt,
const std::locale& loc);
341#if defined(__xtd__cpp_lib_char8_t)
342 std::string
to_string(
const std::u8string& value,
const std::string& fmt,
const std::locale& loc);
344 std::string
to_string(
const std::u16string& value,
const std::string& fmt,
const std::locale& loc);
345 std::string
to_string(
const std::u32string& value,
const std::string& fmt,
const std::locale& loc);
346 std::string
to_string(
const std::wstring& value,
const std::string& fmt,
const std::locale& loc);
358 template<
typename value_t>
359 inline std::string
to_string(
const value_t& value,
const std::string& fmt) {
return to_string(value, fmt, std::locale());}
362 inline std::string
to_string(
const char* value,
const std::string& fmt) {
return to_string(value, fmt, std::locale());}
365#if defined(__xtd__cpp_lib_three_way_comparison)
367 inline std::string
to_string(
const std::partial_ordering& value,
const std::string& fmt,
const std::locale& loc) {
368 if (value == std::partial_ordering::less)
return "less";
369 if (value == std::partial_ordering::greater)
return "greater";
374 inline std::string
to_string(
const std::strong_ordering& value,
const std::string& fmt,
const std::locale& loc) {
375 if (value == std::strong_ordering::less)
return "less";
376 if (value == std::strong_ordering::greater)
return "greater";
381 inline std::string
to_string(
const std::weak_ordering& value,
const std::string& fmt,
const std::locale& loc) {
382 if (value == std::weak_ordering::less)
return "less";
383 if (value == std::weak_ordering::greater)
return "greater";
388 template<
typename value_t>
389 inline std::string
to_string(
const value_t* value,
const std::string& fmt,
const std::locale& loc) {
390 if (!value)
return "(null)";
391 return __numeric_formatter(fmt,
reinterpret_cast<intptr>(value), loc);
394 template<
typename value_t>
395 inline std::string
to_string(value_t*
const value,
const std::string& fmt,
const std::locale& loc) {
396 if (!value)
return "(null)";
397 return __numeric_formatter(fmt,
reinterpret_cast<intptr>(value), loc);
400 template<
typename type_t>
401 inline std::string
to_string(
const std::shared_ptr<type_t>& value,
const std::string& fmt,
const std::locale& loc) {
402 if (!value)
return "(null)";
403 return __numeric_formatter(fmt,
reinterpret_cast<intptr>(value.get()), loc);
406 template<
typename type_t>
407 inline std::string
to_string(
const std::unique_ptr<type_t>& value,
const std::string& fmt,
const std::locale& loc) {
408 if (!value)
return "(null)";
409 return __numeric_formatter(fmt,
reinterpret_cast<intptr>(value.get()), loc);
413 inline std::string
to_string(
const std::any& value,
const std::string& fmt,
const std::locale& loc) {
414 auto iterator = __any_stringer__.find(std::type_index(value.type()));
415 return iterator != __any_stringer__.cend() ?
xtd::to_string(iterator->second(value), fmt, loc) :
"(unregistered)";
418 template<
typename type_t>
419 inline std::string
to_string(
const std::optional<type_t>& value,
const std::string& fmt,
const std::locale& loc) {
return !value.has_value() ?
"(null)" : std::string {
"("} +
to_string(value.value(), fmt, loc) + std::string {
")"};}
422 inline std::string
to_string(
const std::nullopt_t& value,
const std::string& fmt,
const std::locale& loc) {
return "(null)";}
424 template<
typename type1_t,
typename type2_t>
425 inline std::string
to_string(
const std::pair<type1_t, type2_t>& value,
const std::string& fmt,
const std::locale& loc) {
426 return std::string {
"("} +
to_string(value.first, fmt, loc) + std::string {
", "} +
to_string(value.second, fmt, loc) + std::string {
")"};
429 template<
typename type_t,
unsigned n_t,
unsigned last_t>
431 static std::string to_string(
const std::string& str,
const type_t& value,
const std::string& fmt,
const std::locale& loc) {
return __xtd_tuple_stringer<type_t, n_t + 1, last_t >::to_string(str +
xtd::to_string(std::get<n_t>(value), fmt, loc) +
", ", value, fmt, loc);}
434 template<
typename type_t,
unsigned n_t>
436 static std::string to_string(
const std::string& str,
const type_t& value,
const std::string& fmt,
const std::locale& loc) {
return str +
xtd::to_string(std::get<n_t>(value), fmt, loc);}
439 template<
typename ... types_t>
440 inline std::string
to_string(
const std::tuple<types_t ...>& value,
const std::string& fmt,
const std::locale& loc) {
return __xtd_tuple_stringer<std::tuple<types_t ...>, 0,
sizeof...(types_t) - 1 >
::to_string(std::string {
"("}, value, fmt, loc) +
")";}
442 template<
typename iterator_t>
443 inline std::string __xtd_iterator_to_string(
const std::string& str, iterator_t iterator,
const iterator_t& begin,
const iterator_t&
end,
const std::string& fmt,
const std::locale& loc) {
444 if (iterator ==
end)
return str;
445 auto new_str = str + (iterator == begin ? std::string {} : std::string {
", "}) +
xtd::to_string(*iterator, fmt, loc);
446 return __xtd_iterator_to_string(new_str, ++iterator, begin,
end, fmt, loc);
449 template<
typename iterator_t>
450 inline std::string __xtd_sequence_container_to_string(
const iterator_t& begin,
const iterator_t&
end,
const std::string& fmt,
const std::locale& loc) {
return __xtd_iterator_to_string(
"[", begin, begin,
end, fmt, loc) +
"]";}
452 template<
typename type_t,
size_t size>
453 inline std::string
to_string(
const std::array<type_t, size>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);}
455 template<
typename type_t,
typename allocator_t>
456 inline std::string
to_string(
const std::deque<type_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);}
458 template<
typename type_t,
typename allocator_t>
459 inline std::string
to_string(
const std::forward_list<type_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);}
461 template<
typename type_t>
462 inline std::string
to_string(
const std::initializer_list<type_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);}
464 template<
typename type_t,
typename allocator_t>
465 inline std::string
to_string(
const std::list<type_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);}
467 template<
typename type_t>
468 inline std::string
to_string(
const std::valarray<type_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_sequence_container_to_string(std::begin(values), std::end(values), fmt, loc);}
470 template<
typename type_t,
typename allocator_t>
471 inline std::string
to_string(
const std::vector<type_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);}
473 template<
typename iterator_t>
474 inline std::string __xtd_associative_container_to_string(
const iterator_t& begin,
const iterator_t&
end,
const std::string& fmt,
const std::locale& loc) {
return __xtd_iterator_to_string(
"{", begin, begin,
end, fmt, loc) +
"}";}
476 template<
typename key_t,
typename value_t,
typename compare_t,
typename allocator_t>
477 inline std::string
to_string(
const std::map<key_t, value_t, compare_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);}
479 template<
typename key_t,
typename value_t,
typename compare_t,
typename allocator_t>
480 inline std::string
to_string(
const std::multimap<key_t, value_t, compare_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);}
482 template<
typename key_t,
typename compare_t,
typename allocator_t>
483 inline std::string
to_string(
const std::multiset<key_t, compare_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);}
485 template<
typename key_t,
typename compare_t,
typename allocator_t>
486 inline std::string
to_string(
const std::set<key_t, compare_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);}
488 template<
typename key_t,
typename value_t,
typename compare_t,
typename allocator_t>
489 inline std::string
to_string(
const std::unordered_map<key_t, value_t, compare_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);}
491 template<
typename key_t,
typename value_t,
typename compare_t,
typename allocator_t>
492 inline std::string
to_string(
const std::unordered_multimap<key_t, value_t, compare_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);}
494 template<
typename key_t,
typename compare_t,
typename allocator_t>
495 inline std::string
to_string(
const std::unordered_multiset<key_t, compare_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);}
497 template<
typename key_t,
typename compare_t,
typename allocator_t>
498 inline std::string
to_string(
const std::unordered_set<key_t, compare_t, allocator_t>& values,
const std::string& fmt,
const std::locale& loc) {
return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);}
510 template<
typename value_t>
511 inline std::wstring
to_string(
const value_t& value,
const std::wstring& fmt,
const std::locale& loc) {
return __to_string_polymorphic(value, fmt, loc, std::is_polymorphic<value_t>());}
524 inline std::wstring
to_string(
const bool& value,
const std::wstring& fmt,
const std::locale& loc) {
return __boolean_formatter(fmt, value, loc);}
537 inline std::wstring
to_string(
const sbyte& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
550 inline std::wstring
to_string(
const char& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
563 inline std::wstring
to_string(
const unsigned char& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
576 inline std::wstring
to_string(
const short& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
589 inline std::wstring
to_string(
const unsigned short& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
602 inline std::wstring
to_string(
const int& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
615 inline std::wstring
to_string(
const unsigned int& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
628 inline std::wstring
to_string(
const long& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
641 inline std::wstring
to_string(
const unsigned long& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
654 inline std::wstring
to_string(
const long long& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
667 inline std::wstring
to_string(
const unsigned long long& value,
const std::wstring& fmt,
const std::locale& loc) {
return __numeric_formatter(fmt, value, loc);}
680 inline std::wstring
to_string(
const float& value,
const std::wstring& fmt,
const std::locale& loc) {
return __floating_point_formatter(fmt, value, loc);}
693 inline std::wstring
to_string(
const double& value,
const std::wstring& fmt,
const std::locale& loc) {
return __floating_point_formatter(fmt, value, loc);}
706 inline std::wstring
to_string(
const long double& value,
const std::wstring& fmt,
const std::locale& loc) {
return __floating_point_formatter(fmt, value, loc);}
719 inline std::wstring
to_string(
const std::chrono::system_clock::time_point& value,
const std::wstring& fmt,
const std::locale& loc) {
return __date_time_formatter(fmt, std::chrono::system_clock::to_time_t(value), std::chrono::duration_cast<std::chrono::milliseconds>(value.time_since_epoch()).count() % 1000000000, loc);}
732 inline std::wstring
to_string(
const std::tm& value,
const std::wstring& fmt,
const std::locale& loc) {
return __date_time_formatter(fmt, value, 0, loc);}
744 template<
typename type_t,
typename Period>
745 inline std::wstring
to_string(
const std::chrono::duration<type_t, Period>& value,
const std::wstring& fmt,
const std::locale& loc) {
return __duration_formatter(fmt, value, loc);}
748 template<
typename char_t,
typename value_t>
749 inline std::basic_string<char_t> __string_formatter(
const std::basic_string<char_t>& fmt, value_t value,
const std::locale& loc) {
750 return __format_stringer<char_t>(value);
765 inline std::wstring
to_string(
const std::wstring& value,
const std::wstring& fmt,
const std::locale& loc) {
return __string_formatter(fmt, value, loc);}
767#if defined(__xtd__cpp_lib_char8_t)
779 inline std::wstring
to_string(
const char8& value,
const std::wstring& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
793 inline std::wstring
to_string(
const char16& value,
const std::wstring& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
806 inline std::wstring
to_string(
const char32& value,
const std::wstring& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
819 inline std::wstring
to_string(
const wchar& value,
const std::wstring& fmt,
const std::locale& loc) {
return __character_formatter(fmt, value, loc);}
822 inline std::wstring
to_string(
const wchar* value,
const std::wstring& fmt,
const std::locale& loc) {
return __string_formatter(fmt, value, loc);}
834 template<
typename value_t>
835 inline std::wstring
to_string(
const value_t& value,
const std::wstring& fmt) {
return to_string(value, fmt, std::locale());}
838 inline std::wstring
to_string(
const wchar* value,
const std::wstring& fmt) {
return to_string(value, fmt, std::locale());}
Contains __xtd_std_version definitions.
Represents text as a sequence of character units.
Definition basic_string.hpp:79
Contains generic stream output methods.
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:27
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
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:26
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.hpp:41
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::register_any_stringer and xtd::unregister_any_stringer method.
Definition to_string.hpp:430
Contains xtd fundamental types.