xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
to_string.h
Go to the documentation of this file.
1 #pragma once
5 
7 #define __XTD_CORE_INTERNAL__
8 #include "internal/__binary_formatter.h"
9 #include "internal/__boolean_formatter.h"
10 #include "internal/__character_formatter.h"
11 #include "internal/__currency_formatter.h"
12 #include "internal/__date_time_formatter.h"
13 #include "internal/__duration_formatter.h"
14 #include "internal/__enum_formatter.h"
15 #include "internal/__fixed_point_formatter.h"
16 #include "internal/__natural_formatter.h"
17 #include "internal/__numeric_formatter.h"
18 #include "internal/__string_formatter.h"
19 #undef __XTD_CORE_INTERNAL__
20 #include <string>
22 #include "types.h"
23 
25 namespace xtd {
36  template<typename value_t>
37  inline std::string to_string(const value_t& value, const std::string& fmt, const std::locale& loc) {return __to_string_enum(value, fmt, loc, std::is_enum<value_t>());}
38 
49  template<>
50  inline std::string to_string(const bool& value, const std::string& fmt, const std::locale& loc) {return __boolean_formatter(fmt, value, loc);}
51 
62  template<>
63  inline std::string to_string(const int8_t& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
64 
75  template<>
76  inline std::string to_string(const char& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
77 
88  template<>
89  inline std::string to_string(const unsigned char& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
90 
101  template<>
102  inline std::string to_string(const short& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
103 
114  template<>
115  inline std::string to_string(const unsigned short& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
116 
127  template<>
128  inline std::string to_string(const int& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
129 
140  template<>
141  inline std::string to_string(const unsigned int& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
142 
153  template<>
154  inline std::string to_string(const long& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
155 
166  template<>
167  inline std::string to_string(const unsigned long& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
168 
179  template<>
180  inline std::string to_string(const long long& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
181 
192  template<>
193  inline std::string to_string(const unsigned long long& value, const std::string& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
194 
205  template<>
206  inline std::string to_string(const float& value, const std::string& fmt, const std::locale& loc) {return __fixed_point_formatter(fmt, value, loc);}
207 
218  template<>
219  inline std::string to_string(const double& value, const std::string& fmt, const std::locale& loc) {return __fixed_point_formatter(fmt, value, loc);}
220 
231  template<>
232  inline std::string to_string(const long double& value, const std::string& fmt, const std::locale& loc) {return __fixed_point_formatter(fmt, value, loc);}
233 
244  template<>
245  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), loc);}
246 
257  template<>
258  inline std::string to_string(const std::tm& value, const std::string& fmt, const std::locale& loc) {return __date_time_formatter(fmt, value, loc);}
259 
270  template<typename type_t, typename Period>
271  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);}
272 
283  template<>
284  inline std::string to_string(const char8_t& value, const std::string& fmt, const std::locale& loc) {return __character_formatter(fmt, value, loc);}
285 
296  template<>
297  inline std::string to_string(const char16_t& value, const std::string& fmt, const std::locale& loc) {return __character_formatter(fmt, value, loc);}
298 
309  template<>
310  inline std::string to_string(const char32_t& value, const std::string& fmt, const std::locale& loc) {return __character_formatter(fmt, value, loc);}
311 
322  template<>
323  inline std::string to_string(const wchar_t& value, const std::string& fmt, const std::locale& loc) {return __character_formatter(fmt, value, loc);}
324 
326  std::string to_string(const char* value, const std::string& fmt, const std::locale& loc);
327  std::string to_string(const char8_t* value, const std::string& fmt, const std::locale& loc);
328  std::string to_string(const char16_t* value, const std::string& fmt, const std::locale& loc);
329  std::string to_string(const char32_t* value, const std::string& fmt, const std::locale& loc);
330  std::string to_string(const wchar_t* value, const std::string& fmt, const std::locale& loc);
331  std::string to_string(const std::string& value, const std::string& fmt, const std::locale& loc);
332  std::string to_string(const xtd::ustring& value, const std::string& fmt, const std::locale& loc);
333  std::string to_string(const std::u8string& value, const std::string& fmt, const std::locale& loc);
334  std::string to_string(const std::u16string& value, const std::string& fmt, const std::locale& loc);
335  std::string to_string(const std::u32string& value, const std::string& fmt, const std::locale& loc);
336  std::string to_string(const std::wstring& value, const std::string& fmt, const std::locale& loc);
338 
348  template<typename value_t>
349  inline std::string to_string(const value_t& value, const std::string& fmt) {return to_string(value, fmt, std::locale());}
350 
352  inline std::string to_string(const char* value, const std::string& fmt) {return to_string(value, fmt, std::locale());}
354 
365  template<typename value_t>
366  inline std::wstring to_string(const value_t& value, const std::wstring& fmt, const std::locale& loc) {return __to_string_enum(value, fmt, loc, std::is_enum<value_t>());}
367 
378  template<>
379  inline std::wstring to_string(const bool& value, const std::wstring& fmt, const std::locale& loc) {return __boolean_formatter(fmt, value, loc);}
380 
391  template<>
392  inline std::wstring to_string(const int8_t& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
393 
404  template<>
405  inline std::wstring to_string(const char& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
406 
417  template<>
418  inline std::wstring to_string(const unsigned char& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
419 
430  template<>
431  inline std::wstring to_string(const short& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
432 
443  template<>
444  inline std::wstring to_string(const unsigned short& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
445 
456  template<>
457  inline std::wstring to_string(const int& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
458 
469  template<>
470  inline std::wstring to_string(const unsigned int& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
471 
482  template<>
483  inline std::wstring to_string(const long& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
484 
495  template<>
496  inline std::wstring to_string(const unsigned long& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
497 
508  template<>
509  inline std::wstring to_string(const long long& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
510 
521  template<>
522  inline std::wstring to_string(const unsigned long long& value, const std::wstring& fmt, const std::locale& loc) {return __numeric_formatter(fmt, value, loc);}
523 
534  template<>
535  inline std::wstring to_string(const float& value, const std::wstring& fmt, const std::locale& loc) {return __fixed_point_formatter(fmt, value, loc);}
536 
547  template<>
548  inline std::wstring to_string(const double& value, const std::wstring& fmt, const std::locale& loc) {return __fixed_point_formatter(fmt, value, loc);}
549 
560  template<>
561  inline std::wstring to_string(const long double& value, const std::wstring& fmt, const std::locale& loc) {return __fixed_point_formatter(fmt, value, loc);}
562 
573  template<>
574  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), loc);}
575 
586  template<>
587  inline std::wstring to_string(const std::tm& value, const std::wstring& fmt, const std::locale& loc) {return __date_time_formatter(fmt, value, loc);}
588 
599  template<typename type_t, typename Period>
600  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);}
601 
612  template<>
613  inline std::wstring to_string(const std::wstring& value, const std::wstring& fmt, const std::locale& loc) {return __string_formatter(fmt, value, loc);}
614 
625  template<>
626  inline std::wstring to_string(const char8_t& value, const std::wstring& fmt, const std::locale& loc) {return __character_formatter(fmt, value, loc);}
627 
638  template<>
639  inline std::wstring to_string(const char16_t& value, const std::wstring& fmt, const std::locale& loc) {return __character_formatter(fmt, value, loc);}
640 
651  template<>
652  inline std::wstring to_string(const char32_t& value, const std::wstring& fmt, const std::locale& loc) {return __character_formatter(fmt, value, loc);}
653 
664  template<>
665  inline std::wstring to_string(const wchar_t& value, const std::wstring& fmt, const std::locale& loc) {return __character_formatter(fmt, value, loc);}
666 
668  inline std::wstring to_string(const wchar_t* value, const std::wstring& fmt, const std::locale& loc) {return __string_formatter(fmt, value, loc);}
670 
680  template<typename value_t>
681  inline std::wstring to_string(const value_t& value, const std::wstring& fmt) {return to_string(value, fmt, std::locale());}
682 
684  inline std::wstring to_string(const wchar_t* value, const std::wstring& fmt) {return to_string(value, fmt, std::locale());}
686 }
687 
Contains xtd fundamental types.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
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.h:37