xtd 1.0.0
Loading...
Searching...
No Matches
to_string_.hpp
Go to the documentation of this file.
1
4#pragma once
6#if !defined(__XTD_TO_STRING_INTERNAL__)
7#error "Do not include this file: Internal use only. Include <xtd/to_string> or <xtd/to_string.hpp> instead."
8#endif
10
11//#include "globalization/culture_info.hpp"
12#include "stream_insertable.hpp"
13#include "to_string.hpp"
14
16template<typename range_t>
17[[nodiscard]] auto __xtd_range_to_string(const range_t& values, const xtd::string& fmt, const std::locale& loc) -> std::string;
18
19template<typename value_t>
20[[nodiscard]] inline auto xtd::to_string(const value_t& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
21 if constexpr(std::is_polymorphic_v<value_t>) return __to_string_polymorphic(value, fmt, loc);
22 else if constexpr(std::is_enum_v<value_t>) return __enum_formatter<char>(fmt, value, loc);
23 #if defined(__xtd__cpp_lib_ranges)
24 else if constexpr(std::ranges::range<value_t> && !std::is_same_v<value_t, xtd::string>) return __xtd_range_to_string(value, fmt, loc);
25 #endif
26 else if constexpr(xtd::stream_insertable<value_t>) {
27 auto ss = std::stringstream {};
28 ss << value;
29 return ss.str();
31}
32
33template<>
34[[nodiscard]] inline auto xtd::to_string(const bool& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
35 return __boolean_formatter(fmt.chars(), value, loc);
36}
37
38template<>
39[[nodiscard]] inline auto xtd::to_string(const sbyte& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
40 return __numeric_formatter(fmt.chars(), value, loc);
41}
42
43template<>
44[[nodiscard]] inline auto xtd::to_string(const char& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
45 return __character_formatter(fmt.chars(), value, loc);
46}
47
48template<>
49[[nodiscard]] inline auto xtd::to_string(const unsigned char& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
50 return __numeric_formatter(fmt.chars(), value, loc);
51}
52
53template<>
54[[nodiscard]] inline auto xtd::to_string(const short& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
55 return __numeric_formatter(fmt.chars(), value, loc);
56}
57
58template<>
59[[nodiscard]] inline auto xtd::to_string(const unsigned short& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
60 return __numeric_formatter(fmt.chars(), value, loc);
61}
62
63template<>
64[[nodiscard]] inline auto xtd::to_string(const int& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
65 return __numeric_formatter(fmt.chars(), value, loc);
66}
67
68template<>
69[[nodiscard]] inline auto xtd::to_string(const unsigned int& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
70 return __numeric_formatter(fmt.chars(), value, loc);
71}
72
73template<>
74[[nodiscard]] inline auto xtd::to_string(const long& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
75 return __numeric_formatter(fmt.chars(), value, loc);
76}
77
78template<>
79[[nodiscard]] inline auto xtd::to_string(const unsigned long& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
80 return __numeric_formatter(fmt.chars(), value, loc);
81}
82
83template<>
84[[nodiscard]] inline auto xtd::to_string(const long long& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
85 return __numeric_formatter(fmt.chars(), value, loc);
86}
87
88template<>
89[[nodiscard]] inline auto xtd::to_string(const unsigned long long& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
90 return __numeric_formatter(fmt.chars(), value, loc);
91}
92
93template<>
94[[nodiscard]] inline auto xtd::to_string(const float& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
95 return __floating_point_formatter(fmt.chars(), value, loc);
96}
97
98template<>
99[[nodiscard]] inline auto xtd::to_string(const double& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
100 return __floating_point_formatter(fmt.chars(), value, loc);
101}
102
103template<>
104[[nodiscard]] inline auto xtd::to_string(const long double& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
105 return __floating_point_formatter(fmt.chars(), value, loc);
106}
107
108template<>
109[[nodiscard]] inline auto xtd::to_string(const std::chrono::system_clock::time_point& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
110 return __date_time_formatter(fmt.chars(), std::chrono::system_clock::to_time_t(value), std::chrono::duration_cast<std::chrono::nanoseconds>(value.time_since_epoch()).count() % 1000000000, loc);
111}
112
113template<>
114[[nodiscard]] inline auto xtd::to_string(const std::tm& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
115 return __date_time_formatter(fmt.chars(), value, 0, loc);
116}
117
118template<typename type_t, typename period_t>
119[[nodiscard]] inline auto xtd::to_string(const std::chrono::duration<type_t, period_t>& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
120 return __duration_formatter(fmt.chars(), value, loc);
121}
122
123template<>
124[[nodiscard]] inline auto xtd::to_string(const char8& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
125 return __character_formatter(fmt.chars(), value, loc);
126}
127
128template<>
129[[nodiscard]] inline auto xtd::to_string(const char16& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
130 return __character_formatter(fmt.chars(), value, loc);
131}
132
133template<>
134[[nodiscard]] inline auto xtd::to_string(const char32& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
135 return __character_formatter(fmt.chars(), value, loc);
136}
137
138template<>
139[[nodiscard]] inline auto xtd::to_string(const wchar& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
140 return __character_formatter(fmt.chars(), value, loc);
141}
142
143template<typename value_t>
144[[nodiscard]] inline auto xtd::to_string(const value_t& value, const xtd::string& fmt) -> xtd::string {
145 return to_string(value, fmt, std::locale());
146}
147
148[[nodiscard]] inline auto xtd::to_string(const char* value, const xtd::string& fmt) -> xtd::string {
149 return to_string(value, fmt, std::locale());
150}
151
152template<>
153[[nodiscard]] inline auto xtd::to_string(const std::partial_ordering& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
154 if (value == std::partial_ordering::less) return "less";
155 if (value == std::partial_ordering::greater) return "greater";
156 return "equivalent";
157}
158
159template<>
160[[nodiscard]] inline auto xtd::to_string(const std::strong_ordering& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
161 if (value == std::strong_ordering::less) return "less";
162 if (value == std::strong_ordering::greater) return "greater";
163 return "equivalent";
164}
165
166template<>
167[[nodiscard]] inline auto xtd::to_string(const std::weak_ordering& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
168 if (value == std::weak_ordering::less) return "less";
169 if (value == std::weak_ordering::greater) return "greater";
170 return "equivalent";
171}
172
173template<typename value_t>
174[[nodiscard]] inline auto xtd::to_string(const value_t* value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
175 if (!value) return "(null)";
176 return __numeric_formatter(fmt.chars(), reinterpret_cast<intptr>(value), loc);
177}
178
179template<typename value_t>
180[[nodiscard]] inline auto xtd::to_string(value_t* const value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
181 if (!value) return "(null)";
182 return __numeric_formatter(fmt.chars(), reinterpret_cast<intptr>(value), loc);
183}
184
185template<typename type_t>
186[[nodiscard]] inline auto xtd::to_string(const std::shared_ptr<type_t>& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
187 if (!value) return "(null)";
188 return __numeric_formatter(fmt.chars(), reinterpret_cast<intptr>(value.get()), loc);
189}
190
191template<typename type_t>
192[[nodiscard]] inline auto xtd::to_string(const std::unique_ptr<type_t>& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
193 if (!value) return "(null)";
194 return __numeric_formatter(fmt.chars(), reinterpret_cast<intptr>(value.get()), loc);
195}
196
197template<>
198[[nodiscard]] inline auto xtd::to_string(const xtd::any& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
199 auto iterator = __any_stringer__.find(std::type_index(value.type()));
200 return iterator != __any_stringer__.cend() ? xtd::to_string(iterator->second(value), fmt, loc) : "(unregistered)";
201}
202
203template<typename type_t>
204[[nodiscard]] inline auto xtd::to_string(const std::optional<type_t>& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
205 return !value.has_value() ? "(null)" : std::string {"("} + to_string(value.value(), fmt, loc).chars() + std::string {")"};
206}
207
208template<>
209[[nodiscard]] inline auto xtd::to_string(const std::nullopt_t& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
210 return "(null)";
211}
212
213template<>
214[[nodiscard]] inline auto xtd::to_string(const std::nullptr_t&, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
215 return "null";
216}
217
218template<typename type1_t, typename type2_t>
219[[nodiscard]] inline auto xtd::to_string(const std::pair<type1_t, type2_t>& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
220 return std::string {"("} + to_string(value.first, fmt, loc).chars() + std::string {", "} + to_string(value.second, fmt, loc).chars() + std::string {")"};
221}
222
223template<typename type_t, unsigned n_t, unsigned last_t>
224[[nodiscard]] inline auto xtd::__xtd_tuple_stringer<type_t, n_t, last_t>::to_string(const std::string& str, const type_t& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
225 return __xtd_tuple_stringer < type_t, n_t + 1, last_t >::to_string(str + xtd::to_string(std::get<n_t>(value), fmt, loc).chars() + ", ", value, fmt, loc);
226}
227
228template<typename type_t, unsigned n_t>
229[[nodiscard]] inline auto xtd::__xtd_tuple_stringer<type_t, n_t, n_t>::to_string(const std::string& str, const type_t& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
230 return str + xtd::to_string(std::get<n_t>(value), fmt, loc).chars();
231}
232
233template<typename ...types_t>
234[[nodiscard]] inline auto xtd::to_string(const std::tuple<types_t ...>& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
235 return __xtd_tuple_stringer < std::tuple<types_t ...>, 0, sizeof...(types_t) - 1 >::to_string(std::string {"("}, value, fmt, loc) + ")";
236}
237
238template<typename iterator_t>
239[[nodiscard]] inline auto __xtd_iterator_to_string(const std::string& str, iterator_t iterator, const iterator_t& begin, const iterator_t& end, const xtd::string& fmt, const std::locale& loc) -> std::string {
240 if (iterator == end) return str;
241 auto new_str = str + (iterator == begin ? std::string {} : std::string {", "}) + xtd::to_string(*iterator, fmt, loc).chars();
242 return __xtd_iterator_to_string(new_str, ++iterator, begin, end, fmt, loc);
243}
244
245template<typename iterator_t>
246[[nodiscard]] inline auto __xtd_sequence_container_to_string(const iterator_t& begin, const iterator_t& end, const xtd::string& fmt, const std::locale& loc) -> std::string {
247 return __xtd_iterator_to_string("[", begin, begin, end, fmt, loc) + "]";
248}
249
250template<typename range_t>
251[[nodiscard]] inline auto __xtd_range_to_string(const range_t& values, const xtd::string& fmt, const std::locale& loc) -> std::string {
252 std::ostringstream oss;
253 oss.imbue(loc);
254 oss << "[";
255 bool first = true;
256 for (auto&& v : values) {
257 if (!first) oss << ", ";
258 first = false;
259 oss << xtd::to_string(v, fmt, loc);
260 }
261 oss << "]";
262 return oss.str();
263}
264
265template<typename type_t, xtd::usize size>
266[[nodiscard]] inline auto xtd::to_string(const std::array<type_t, size>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
267 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
268}
269
270template<xtd::usize size>
271[[nodiscard]] inline auto xtd::to_string(const std::bitset<size>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
272 auto result = xtd::string {"["};
273 for (auto index = xtd::usize {0}; index < values.length(); ++index)
274 result += (index ? ", " : "") + to_string(static_cast<bool>(values[index]), fmt, loc);
275 return result + "]";
276}
277
278template<typename type_t, typename allocator_t>
279[[nodiscard]] inline auto xtd::to_string(const std::deque<type_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
280 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
281}
282
283template<typename type_t, typename allocator_t>
284[[nodiscard]] inline auto xtd::to_string(const std::forward_list<type_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
285 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
286}
287
288template<typename type_t>
289[[nodiscard]] inline auto xtd::to_string(const std::initializer_list<type_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
290 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
291}
292
293template<typename type_t, typename allocator_t>
294[[nodiscard]] inline auto xtd::to_string(const std::list<type_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
295 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
296}
297
298template<typename type_t, typename container_t>
299[[nodiscard]] inline auto xtd::to_string(const std::queue<type_t, container_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
300 struct std_queue : public std::queue<type_t> {
301 std_queue(const std::queue<type_t>& queue) : ptr {reinterpret_cast<const std_queue*>(&queue)} {}
302 auto begin() const {return ptr->c.begin();}
303 auto end() const {return ptr->c.end();}
304 const std_queue* ptr;
305 };
306 auto items = std_queue {values};
307 return __xtd_sequence_container_to_string(items.begin(), items.end(), fmt, loc);
308}
309
310template<typename type_t, typename container_t>
311[[nodiscard]] inline auto xtd::to_string(const std::priority_queue<type_t, container_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
312 struct std_priority_queue : public std::queue<type_t> {
313 std_priority_queue(const std::priority_queue<type_t>& queue) : ptr {reinterpret_cast<const std_priority_queue*>(&queue)} {}
314 auto begin() const {return ptr->c.begin();}
315 auto end() const {return ptr->c.end();}
316 const std_priority_queue* ptr;
317 };
318 auto items = std_priority_queue {values};
319 return __xtd_sequence_container_to_string(items.begin(), items.end(), fmt, loc);
320}
321
322template<typename type_t, typename container_t>
323[[nodiscard]] inline auto xtd::to_string(const std::stack<type_t, container_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
324 struct std_stack : public std::stack<type_t> {
325 std_stack(const std::stack<type_t>& queue) : ptr {reinterpret_cast<const std_stack*>(&queue)} {}
326 auto begin() const {return ptr->c.begin();}
327 auto end() const {return ptr->c.end();}
328 const std_stack* ptr;
329 };
330 auto items = std_stack {values};
331 return __xtd_sequence_container_to_string(items.begin(), items.end(), fmt, loc);
332}
333
334template<typename type_t>
335[[nodiscard]] inline auto xtd::to_string(const std::valarray<type_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
336 return __xtd_sequence_container_to_string(std::begin(values), std::end(values), fmt, loc);
337}
338
339template<typename type_t, typename allocator_t>
340[[nodiscard]] inline auto xtd::to_string(const std::vector<type_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
341 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
342}
343
344template<typename iterator_t>
345[[nodiscard]] inline auto __xtd_associative_container_to_string(const iterator_t& begin, const iterator_t& end, const xtd::string& fmt, const std::locale& loc) -> std::string {
346 return __xtd_iterator_to_string("{", begin, begin, end, fmt, loc) + "}";
347}
348
349template<typename key_t, typename value_t, typename compare_t, typename allocator_t>
350[[nodiscard]] inline auto xtd::to_string(const std::map<key_t, value_t, compare_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
351 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
352}
353
354template<typename key_t, typename value_t, typename compare_t, typename allocator_t>
355[[nodiscard]] inline auto xtd::to_string(const std::multimap<key_t, value_t, compare_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
356 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
357}
358
359template<typename key_t, typename compare_t, typename allocator_t>
360[[nodiscard]] inline auto xtd::to_string(const std::multiset<key_t, compare_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
361 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
362}
363
364template<typename key_t, typename compare_t, typename allocator_t>
365[[nodiscard]] inline auto xtd::to_string(const std::set<key_t, compare_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
366 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
367}
368
369template<typename key_t, typename value_t, typename compare_t, typename allocator_t>
370[[nodiscard]] inline auto xtd::to_string(const std::unordered_map<key_t, value_t, compare_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
371 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
372}
373
374template<typename key_t, typename value_t, typename compare_t, typename allocator_t>
375[[nodiscard]] inline auto xtd::to_string(const std::unordered_multimap<key_t, value_t, compare_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
376 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
377}
378
379template<typename key_t, typename compare_t, typename allocator_t>
380[[nodiscard]] inline auto xtd::to_string(const std::unordered_multiset<key_t, compare_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
381 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
382}
383
384template<typename key_t, typename compare_t, typename allocator_t>
385[[nodiscard]] inline auto xtd::to_string(const std::unordered_set<key_t, compare_t, allocator_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
386 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
387}
388
389template<typename ...args_t>
390[[nodiscard]] inline auto xtd::to_string(const std::variant<args_t...>& value, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
391 if (value.valueless_by_exception()) return "(valueless_by_exception)";
392 return std::visit([&](auto && t){return xtd::to_string(t, fmt, loc);}, value);
393}
394
395template<typename type_t>
396[[nodiscard]] inline auto xtd::to_string(type_t value, const std::initializer_list<std::pair<type_t, xtd::string>>& il) -> xtd::string {
397 std::map<type_t, xtd::string, std::greater<type_t>> values;
398 for (const auto& item : il) values[item.first] = item.second;
399 return to_string(value, values);
400}
401
402#if defined(__xtd__cpp_lib_ranges)
403template <std::ranges::range range_t>
404[[nodiscard]] inline auto to_string(const range_t& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
405 return __xtd_range_to_string(values, fmt, loc);
406}
407#endif
408
409template<typename type_t>
410[[nodiscard]] inline auto xtd::to_string(const xtd::collections::generic::ienumerable<type_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
411 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
412}
413
414template<typename type_t>
415[[nodiscard]] inline auto xtd::to_string(const xtd::collections::generic::helpers::raw_array<type_t>& values, const xtd::string& fmt, const std::locale& loc) -> xtd::string {
416 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
417}
418
419template<typename type_t, typename string_t>
420[[nodiscard]] inline auto xtd::to_string(type_t value, const std::map<type_t, string_t, std::greater<type_t>>& values) -> string_t {
421 auto it = values.find(value);
422 if (it != values.end()) return it->second;
423 string_t result;
424 long long rest = static_cast<long long>(value);
425 for (const auto& item : values) {
426 if (static_cast<long long>(item.first) != 0 && (rest & static_cast<long long>(item.first)) == static_cast<long long>(item.first)) {
427 if (!result.empty()) result = string_t {',', ' '} + result;
428 result = item.second + result;
429 rest -= static_cast<long long>(item.first);
430 }
431 }
432 if (!result.empty()) return result;
433 return to_string(static_cast<long long>(value), string_t {'G'}, std::locale());
434}
435
436template<typename type_t, typename string_t>
437[[nodiscard]] inline auto xtd::to_string(type_t value, const std::map<type_t, string_t>& values) -> string_t {
438 std::map<type_t, string_t, std::greater<type_t>> descending_values;
439 for (const auto& item : values) descending_values[item.first] = item.second;
440 return to_string(value, descending_values);
441}
442
443template<typename char_t, typename value_t>
444[[nodiscard]] inline auto __string_formatter(const std::basic_string<char_t>& fmt, value_t value, const std::locale& loc) -> std::basic_string<char_t> {
445 return __format_stringer<char_t>(value);
446}
447
448template<>
449[[nodiscard]] inline auto __format_stringer<char, bool&>(bool& value) -> std::string {
450 return xtd::to_string(value, "G", std::locale());
451}
452
453template<>
454[[nodiscard]] inline auto __format_stringer<char, xtd::sbyte&>(xtd::sbyte& value) -> std::string {
455 return xtd::to_string(value, "G", std::locale());
456}
457
458template<>
459[[nodiscard]] inline auto __format_stringer<char, const unsigned char&>(const unsigned char& value) -> std::string {
460 return xtd::to_string(value, "G", std::locale());
461}
462
463template<>
464[[nodiscard]] inline auto __format_stringer<char, unsigned char&>(unsigned char& value) -> std::string {
465 return xtd::to_string(value, "G", std::locale());
466}
467
468template<>
469[[nodiscard]] inline auto __format_stringer<char, short&>(short& value) -> std::string {
470 return xtd::to_string(value, "G", std::locale());
471}
472
473template<>
474[[nodiscard]] inline auto __format_stringer<char, unsigned short&>(unsigned short& value) -> std::string {
475 return xtd::to_string(value, "G", std::locale());
476}
477
478template<>
479[[nodiscard]] inline auto __format_stringer<char, int&>(int& value) -> std::string {
480 return xtd::to_string(value, "G", std::locale());
481}
482
483template<>
484[[nodiscard]] inline auto __format_stringer<char, unsigned int&>(unsigned int& value) -> std::string {
485 return xtd::to_string(value, "G", std::locale());
486}
487
488template<>
489[[nodiscard]] inline auto __format_stringer<char, long&>(long& value) -> std::string {
490 return xtd::to_string(value, "G", std::locale());
491}
492
493template<>
494[[nodiscard]] inline auto __format_stringer<char, unsigned long&>(unsigned long& value) -> std::string {
495 return xtd::to_string(value, "G", std::locale());
496}
497
498template<>
499[[nodiscard]] inline auto __format_stringer<char, long long&>(long long& value) -> std::string {
500 return xtd::to_string(value, "G", std::locale());
501}
502
503template<>
504[[nodiscard]] inline auto __format_stringer<char, unsigned long long&>(unsigned long long& value) -> std::string {
505 return xtd::to_string(value, "G", std::locale());
506}
507
508template<>
509[[nodiscard]] inline auto __format_stringer<char, float&>(float& value) -> std::string {
510 return xtd::to_string(value, "G", std::locale());
511}
512
513template<>
514[[nodiscard]] inline auto __format_stringer<char, double&>(double& value) -> std::string {
515 return xtd::to_string(value, "G", std::locale());
516}
517
518template<>
519[[nodiscard]] inline auto __format_stringer<char, long double&>(long double& value) -> std::string {
520 return xtd::to_string(value, "G", std::locale());
521}
522
523template<>
524[[nodiscard]] inline auto __format_stringer<char, std::chrono::system_clock::time_point&>(std::chrono::system_clock::time_point& value) -> std::string {
525 return xtd::to_string(value, "G", std::locale());
526}
527
528template<>
529[[nodiscard]] inline auto __format_stringer<char, std::tm&>(tm& value) -> std::string {
530 return xtd::to_string(value, "G", std::locale());
531}
532
533template<>
534[[nodiscard]] inline auto __format_stringer<char, xtd::wchar&>(xtd::wchar& value) -> std::string {
535 return xtd::to_string(value, "G", std::locale());
536}
537
538template<>
539[[nodiscard]] inline auto __format_stringer<char, xtd::char8&>(xtd::char8& value) -> std::string {
540 return xtd::to_string(value, "G", std::locale());
541}
542
543template<>
544[[nodiscard]] inline auto __format_stringer<char, xtd::char16&>(xtd::char16& value) -> std::string {
545 return xtd::to_string(value, "G", std::locale());
546}
547
548template<>
549[[nodiscard]] inline auto __format_stringer<char, xtd::char32&>(xtd::char32& value) -> std::string {
550 return xtd::to_string(value, "G", std::locale());
551}
552
553template<typename char_t, typename type_t, typename period_t = std::ratio<1>>
554auto operator <<(std::basic_ostream<char_t>& os, const std::chrono::duration<type_t, period_t>& value) -> std::basic_ostream<char_t>& {
555 return os << xtd::to_string(value, std::basic_string<char_t> {'G'}, std::locale());
556}
557
558template < class char_t, typename type_t >
559struct __enum_ostream__<char_t, type_t, std::false_type> {
560 auto to_stream(std::basic_ostream < char_t >& os, const type_t& value) noexcept -> std::basic_ostream<char_t>& {
561 //return os << value;
562 return os << xtd::to_string(value, std::basic_string < char_t > {}, std::locale {});
563 }
564};
Internal vector-like container used as a storage backend for xtd collections.
Definition raw_array.hpp:29
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Definition stream_insertable.hpp:13
generic::queue< xtd::any_object > queue
Represents a first-in, first-out collection of objects.
Definition queue.hpp:27
@ value
Represnets the constant operator precedence (42).
Definition operator_precedence.hpp:30
@ format
The format is not valid.
Definition exception_case.hpp:51
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
std::int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
std::intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
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
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > iterator
Represents the iterator of read_only_span value type.
Definition read_only_span.hpp:71
auto first() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:249
auto begin() const -> const_iterator
Returns an iterator to the beginning.
Definition read_only_span.hpp:186
auto to_string() const noexcept -> xtd::string override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:342
auto end() const -> const_iterator
Returns an iterator to the end.
Definition read_only_span.hpp:205
Contains xtd::stream_insertable concept.
Contains xtd::to_string methods.