xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
default_insert_basic_ostream_operator.h
Go to the documentation of this file.
1
4#pragma once
5#include <array>
6#include <cstdint>
7#include <deque>
8#include <exception>
9#include <forward_list>
10#include <initializer_list>
11#include <iomanip>
12#include <iostream>
13#include <list>
14#include <map>
15#include <optional>
16#include <set>
17#include <stdexcept>
18#include <string>
19#include <sstream>
20#include <type_traits>
21#include <tuple>
22#include <unordered_map>
23#include <unordered_set>
24#include <utility>
25#include <vector>
26#include <xtd/ustring.h>
27
29template<class type_t> struct __tunit_is_printable : std::false_type {};
30template<> struct __tunit_is_printable<bool> : std::true_type {};
31template<> struct __tunit_is_printable<char> : std::true_type {};
32template<> struct __tunit_is_printable<signed char> : std::true_type {};
33template<> struct __tunit_is_printable<unsigned char> : std::true_type {};
34template<> struct __tunit_is_printable<wchar_t> : std::true_type {};
35template<> struct __tunit_is_printable<char8_t> : std::true_type {};
36template<> struct __tunit_is_printable<char16_t> : std::true_type {};
37template<> struct __tunit_is_printable<char32_t> : std::true_type {};
38template<> struct __tunit_is_printable<short> : std::true_type {};
39template<> struct __tunit_is_printable<unsigned short> : std::true_type {};
40template<> struct __tunit_is_printable<int> : std::true_type {};
41template<> struct __tunit_is_printable<unsigned int> : std::true_type {};
42template<> struct __tunit_is_printable<long> : std::true_type {};
43template<> struct __tunit_is_printable<unsigned long> : std::true_type {};
44template<> struct __tunit_is_printable<long long> : std::true_type {};
45template<> struct __tunit_is_printable<unsigned long long> : std::true_type {};
46template<> struct __tunit_is_printable<const char*> : std::true_type {};
47template<> struct __tunit_is_printable<const wchar_t*> : std::true_type {};
48template<> struct __tunit_is_printable<float> : std::true_type {};
49template<> struct __tunit_is_printable<double> : std::true_type {};
50template<> struct __tunit_is_printable<long double> : std::true_type {};
51template<> struct __tunit_is_printable<std::string> : std::true_type {};
52template<> struct __tunit_is_printable<xtd::ustring> : std::true_type {};
53template<> struct __tunit_is_printable<std::u8string> : std::true_type {};
54template<> struct __tunit_is_printable<std::u16string> : std::true_type {};
55template<> struct __tunit_is_printable<std::u32string> : std::true_type {};
56template<> struct __tunit_is_printable<std::wstring> : std::true_type {};
57
58template<typename char_t, typename char_traits_t, typename value_t>
59static void __tunit_print_value(std::basic_ostream<char_t, char_traits_t>& os, const value_t& value, std::true_type) {
60 os.operator<<(value);
61}
62
63template<typename char_t, typename char_traits_t, typename value_t>
64static void __tunit_print_value(std::basic_ostream<char_t, char_traits_t>& os, value_t* value, std::true_type) {
65 os.operator<<(value);
66}
67
68template<typename char_t, typename char_traits_t, typename value_t>
69static void __tunit_print_value(std::basic_ostream<char_t, char_traits_t>& os, const value_t* value, std::true_type) {
70 os.operator<<(value);
71}
72
73template<typename char_t, typename char_traits_t, typename value_t>
74static void __tunit_print_value(std::basic_ostream<char_t, char_traits_t>& os, const value_t& value, std::false_type) {
75 size_t size = sizeof(value) > 32 ? 32 : sizeof(value);
76 os << size << "-byte object <";
77 for (size_t index = 0; index != size; index++)
78 os << (index != 0 ? (index % 2 == 0 ? " " : "-") : "") << std::hex << std::setiosflags(std::ios_base::uppercase) << std::setw(2) << std::setfill('0') << static_cast<int>(reinterpret_cast<const unsigned char*>(&value)[index]) << std::resetiosflags(std::ios_base::dec) << std::dec;
79 os << (size < sizeof(value) ? "-..." : "") << ">";
80}
81
82template<typename char_t, typename char_traits_t, typename value_t>
83static void __print(std::basic_ostream<char_t, char_traits_t>& os, const value_t& value) {
84 __tunit_print_value(os, value, __tunit_is_printable<value_t>());
85}
86
87template<typename char_t, typename char_traits_t, typename value_t>
88static void __print(std::basic_ostream<char_t, char_traits_t>& os, value_t* value) {
89 __tunit_print_value(os, value, __tunit_is_printable<value_t>());
90}
91
92template<typename char_t, typename char_traits_t, typename value_t>
93static void __print(std::basic_ostream<char_t, char_traits_t>& os, const value_t* value) {
94 __tunit_print_value(os, value, __tunit_is_printable<value_t>());
95}
96
97template <typename char_t, typename char_traits_t, typename value_t>
98struct __tunit_value_printer {
99 static void print(std::basic_ostream<char_t, char_traits_t>& os, const value_t* & value) {
100 __print(os, value);
101 }
102 static void print(std::basic_ostream<char_t, char_traits_t>& os, const value_t* const & value) {
103 __print(os, value);
104 }
105 static void print(std::basic_ostream<char_t, char_traits_t>& os, const value_t& value) {
106 __print(os, value);
107 }
108};
109
110template <typename char_t, typename char_traits_t>
111struct __tunit_value_printer<char_t, char_traits_t, std::exception> {
112 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::exception& value) {
113 os << "exception: " << value.what();
114 }
115};
116
117template <typename char_t, typename char_traits_t, typename value_t>
118struct __tunit_value_printer<char_t, char_traits_t, std::optional<value_t>> {
119 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::optional<value_t>& value) {
120 if (!value.has_value())
121 os << "(null)";
122 else {
123 os << "(";
124 __tunit_value_printer<char_t, char_traits_t, value_t>::print(os, value.value());
125 os << ")";
126 }
127 }
128};
129
130template <typename char_t, typename char_traits_t>
131struct __tunit_value_printer<char_t, char_traits_t, std::string> {
132 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::string& value) {
133 os << "\"" << value << "\"";
134 }
135};
136
137template <typename char_t, typename char_traits_t>
138struct __tunit_value_printer<char_t, char_traits_t, xtd::ustring> {
139 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::string& value) {
140 os << "\"" << value << "\"";
141 }
142};
143
144template <typename char_t, typename char_traits_t>
145struct __tunit_value_printer<char_t, char_traits_t, std::u8string> {
146 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::u8string& value) {
147 __tunit_value_printer<char_t, char_traits_t, char8_t>::print(os, value.c_str());
148 }
149};
150
151template <typename char_t, typename char_traits_t>
152struct __tunit_value_printer<char_t, char_traits_t, std::u16string> {
153 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::u16string& value) {
154 __tunit_value_printer<char_t, char_traits_t, char16_t>::print(os, value.c_str());
155 }
156};
157
158template <typename char_t, typename char_traits_t>
159struct __tunit_value_printer<char_t, char_traits_t, std::u32string> {
160 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::u32string& value) {
161 __tunit_value_printer<char_t, char_traits_t, char32_t>::print(os, value.c_str());
162 }
163};
164
165template <typename char_t, typename char_traits_t>
166struct __tunit_value_printer<char_t, char_traits_t, std::wstring> {
167 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::wstring& value) {
168 __tunit_value_printer<char_t, char_traits_t, wchar_t>::print(os, value.c_str());
169 }
170};
171
172template <typename char_t, typename char_traits_t>
173struct __tunit_value_printer<char_t, char_traits_t, const char*> {
174 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char* const & value) {
175 os << "\"" << value << "\"";
176 }
177
178 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char* & value) {
179 os << "\"" << value << "\"";
180 }
181
182 static void print(std::basic_ostream<char_t, char_traits_t>& os, char value) {
183 os << value;
184 }
185};
186
187template <typename char_t, typename char_traits_t>
188struct __tunit_value_printer<char_t, char_traits_t, char> {
189 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char* const & value) {
190 os << "\"" << value << "\"";
191 }
192
193 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char* & value) {
194 os << "\"" << value << "\"";
195 }
196
197 static void print(std::basic_ostream<char_t, char_traits_t>& os, char value) {
198 os << value;
199 }
200};
201
202template <typename char_t, typename char_traits_t>
203struct __tunit_value_printer<char_t, char_traits_t, const char8_t*> {
204 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char8_t* const & value) {
205 os << "\"";
206 for (size_t index = 0; value[index] != L'\0'; index++)
207 __tunit_value_printer<char_t, char_traits_t, char8_t>::print(os, value[index]);
208 os << "\"";
209 }
210
211 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char8_t* & value) {
212 os << "\"";
213 for (size_t index = 0; value[index] != L'\0'; index++)
214 __tunit_value_printer<char_t, char_traits_t, char8_t>::print(os, value[index]);
215 os << "\"";
216 }
217
218 static void print(std::basic_ostream<char_t, char_traits_t>& os, char8_t value) {
219 if (value <= 0xFF)
220 os << static_cast<char>(value);
221 else
222 os << "\\x" << std::hex << static_cast<int>(value);
223 }
224};
225
226template <typename char_t, typename char_traits_t>
227struct __tunit_value_printer<char_t, char_traits_t, char8_t> {
228 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char8_t* const & value) {
229 os << "\"";
230 for (size_t index = 0; value[index] != L'\0'; index++)
231 __tunit_value_printer<char_t, char_traits_t, char8_t>::print(os, value[index]);
232 os << "\"";
233 }
234
235 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char8_t* & value) {
236 os << "\"";
237 for (size_t index = 0; value[index] != L'\0'; index++)
238 __tunit_value_printer<char_t, char_traits_t, char8_t>::print(os, value[index]);
239 os << "\"";
240 }
241
242 static void print(std::basic_ostream<char_t, char_traits_t>& os, char8_t value) {
243 os << static_cast<char>(value);
244 }
245};
246
247template <typename char_t, typename char_traits_t>
248struct __tunit_value_printer<char_t, char_traits_t, const char16_t*> {
249 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char16_t* const & value) {
250 os << "\"";
251 for (size_t index = 0; value[index] != L'\0'; index++)
252 __tunit_value_printer<char_t, char_traits_t, char16_t>::print(os, value[index]);
253 os << "\"";
254 }
255
256 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char16_t* & value) {
257 os << "\"";
258 for (size_t index = 0; value[index] != L'\0'; index++)
259 __tunit_value_printer<char_t, char_traits_t, char16_t>::print(os, value[index]);
260 os << "\"";
261 }
262
263 static void print(std::basic_ostream<char_t, char_traits_t>& os, char16_t value) {
264 if (value <= 0xFF)
265 os << static_cast<char>(value);
266 else
267 os << "\\x" << std::hex << static_cast<int>(value);
268 }
269};
270
271template <typename char_t, typename char_traits_t>
272struct __tunit_value_printer<char_t, char_traits_t, char16_t> {
273 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char16_t* const & value) {
274 os << "\"";
275 for (size_t index = 0; value[index] != L'\0'; index++)
276 __tunit_value_printer<char_t, char_traits_t, char16_t>::print(os, value[index]);
277 os << "\"";
278 }
279
280 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char16_t* & value) {
281 os << "\"";
282 for (size_t index = 0; value[index] != L'\0'; index++)
283 __tunit_value_printer<char_t, char_traits_t, char16_t>::print(os, value[index]);
284 os << "\"";
285 }
286
287 static void print(std::basic_ostream<char_t, char_traits_t>& os, char16_t value) {
288 if (value <= 0xFF)
289 os << static_cast<char>(value);
290 else
291 os << "\\x" << std::hex << static_cast<int>(value);
292 }
293};
294
295template <typename char_t, typename char_traits_t>
296struct __tunit_value_printer<char_t, char_traits_t, const char32_t*> {
297 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char32_t* const & value) {
298 os << "\"";
299 for (size_t index = 0; value[index] != L'\0'; index++)
300 __tunit_value_printer<char_t, char_traits_t, char32_t>::print(os, value[index]);
301 os << "\"";
302 }
303
304 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char32_t* & value) {
305 os << "\"";
306 for (size_t index = 0; value[index] != L'\0'; index++)
307 __tunit_value_printer<char_t, char_traits_t, char32_t>::print(os, value[index]);
308 os << "\"";
309 }
310
311 static void print(std::basic_ostream<char_t, char_traits_t>& os, char32_t value) {
312 if (value <= 0xFF)
313 os << static_cast<char>(value);
314 else
315 os << "\\x" << std::hex << static_cast<int>(value);
316 }
317};
318
319template <typename char_t, typename char_traits_t>
320struct __tunit_value_printer<char_t, char_traits_t, char32_t> {
321 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char32_t* const & value) {
322 os << "\"";
323 for (size_t index = 0; value[index] != L'\0'; index++)
324 __tunit_value_printer<char_t, char_traits_t, char32_t>::print(os, value[index]);
325 os << "\"";
326 }
327
328 static void print(std::basic_ostream<char_t, char_traits_t>& os, const char32_t* & value) {
329 os << "\"";
330 for (size_t index = 0; value[index] != L'\0'; index++)
331 __tunit_value_printer<char_t, char_traits_t, char32_t>::print(os, value[index]);
332 os << "\"";
333 }
334
335 static void print(std::basic_ostream<char_t, char_traits_t>& os, char32_t value) {
336 if (value <= 0xFF)
337 os << static_cast<char>(value);
338 else
339 os << "\\x" << std::hex << static_cast<int>(value);
340 }
341};
342
343template <typename char_t, typename char_traits_t>
344struct __tunit_value_printer<char_t, char_traits_t, const wchar_t*> {
345 static void print(std::basic_ostream<char_t, char_traits_t>& os, const wchar_t* const & value) {
346 os << "\"";
347 for (size_t index = 0; value[index] != L'\0'; index++)
348 __tunit_value_printer<char_t, char_traits_t, wchar_t>::print(os, value[index]);
349 os << "\"";
350 }
351
352 static void print(std::basic_ostream<char_t, char_traits_t>& os, const wchar_t* & value) {
353 os << "\"";
354 for (size_t index = 0; value[index] != L'\0'; index++)
355 __tunit_value_printer<char_t, char_traits_t, wchar_t>::print(os, value[index]);
356 os << "\"";
357 }
358
359 static void print(std::basic_ostream<char_t, char_traits_t>& os, wchar_t value) {
360 if (value <= 0xFF)
361 os << static_cast<char>(value);
362 else
363 os << "\\x" << std::hex << static_cast<int>(value);
364 }
365};
366
367template <typename char_t, typename char_traits_t>
368struct __tunit_value_printer<char_t, char_traits_t, wchar_t> {
369 static void print(std::basic_ostream<char_t, char_traits_t>& os, const wchar_t* const & value) {
370 os << "\"";
371 for (size_t index = 0; value[index] != L'\0'; index++)
372 __tunit_value_printer<char_t, char_traits_t, wchar_t>::print(os, value[index]);
373 os << "\"";
374 }
375
376 static void print(std::basic_ostream<char_t, char_traits_t>& os, const wchar_t* & value) {
377 os << "\"";
378 for (size_t index = 0; value[index] != L'\0'; index++)
379 __tunit_value_printer<char_t, char_traits_t, wchar_t>::print(os, value[index]);
380 os << "\"";
381 }
382
383 static void print(std::basic_ostream<char_t, char_traits_t>& os, wchar_t value) {
384 if (value <= 0xFF)
385 os << static_cast<char>(value);
386 else
387 os << "\\x" << std::hex << static_cast<int>(value);
388 }
389};
390
391template <typename char_t, typename char_traits_t, typename type1_t, typename type2_t>
392struct __tunit_value_printer<char_t, char_traits_t, std::pair<type1_t, type2_t>> {
393 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::pair<type1_t, type2_t>& value) {
394 os << "(";
395 __tunit_value_printer<char_t, char_traits_t, type1_t>::print(os, value.first);
396 os << ", ";
397 __tunit_value_printer<char_t, char_traits_t, type2_t>::print(os, value.second);
398 os << ")";
399 }
400};
401
402template<typename char_t, typename char_traits_t, typename type_t, unsigned N, unsigned Last>
403struct __tuple_printer {
404 static void print(std::basic_ostream<char_t, char_traits_t>& os, const type_t& value) {
405 __tunit_value_printer<char_t, char_traits_t, typename std::tuple_element<N, type_t>::type>::print(os, std::get<N>(value));
406 os << ", ";
407 __tuple_printer<char_t, char_traits_t, type_t, N + 1, Last>::print(os, value);
408 }
409};
410
411template<typename char_t, typename char_traits_t, typename type_t, unsigned N>
412struct __tuple_printer<char_t, char_traits_t, type_t, N, N> {
413 static void print(std::basic_ostream<char_t, char_traits_t>& os, const type_t& value) {
414 __tunit_value_printer<char_t, char_traits_t, typename std::tuple_element<N, type_t>::type>::print(os, std::get<N>(value));
415 }
416};
417
418template <typename char_t, typename char_traits_t, typename ... Types>
419struct __tunit_value_printer<char_t, char_traits_t, std::tuple<Types ...>> {
420 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::tuple<Types ...>& value) {
421 os << "(";
422 __tuple_printer<char_t, char_traits_t, std::tuple<Types ...>, 0, sizeof...(Types) - 1>::print(os, value);
423 os << ")";
424 }
425};
426
427template <typename char_t, typename char_traits_t>
428struct __tunit_value_printer<char_t, char_traits_t, std::tuple<>> {
429 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::tuple<>&) {
430 os << "()";
431 }
432};
433
434template <typename char_t, typename char_traits_t, typename Iterator>
435std::basic_ostream<char_t, char_traits_t>& __print_sequence_container(std::basic_ostream<char_t, char_traits_t>& os, const Iterator& begin, const Iterator& end) {
436 os << "[";
437 bool first = true;
438 for (Iterator it = begin; it != end; ++it) {
439 if (!first) os << ", ";
440 __tunit_value_printer<char_t, char_traits_t, typename std::iterator_traits<Iterator>::value_type>::print(os, *it);
441 first = false;
442 }
443 return os << "]";
444}
445
446template <typename char_t, typename char_traits_t, typename value_t, size_t Size>
447struct __tunit_value_printer<char_t, char_traits_t, std::array<value_t, Size>> {
448 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::array<value_t, Size>& values) {
449 __print_sequence_container(os, values.begin(), values.end());
450 }
451};
452
453template <typename char_t, typename char_traits_t, typename value_t>
454struct __tunit_value_printer<char_t, char_traits_t, std::deque<value_t>> {
455 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::deque<value_t>& values) {
456 __print_sequence_container(os, values.begin(), values.end());
457 }
458};
459
460template <typename char_t, typename char_traits_t, typename value_t>
461struct __tunit_value_printer<char_t, char_traits_t, std::forward_list<value_t>> {
462 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::forward_list<value_t>& values) {
463 __print_sequence_container(os, values.begin(), values.end());
464 }
465};
466
467template <typename char_t, typename char_traits_t, typename value_t>
468struct __tunit_value_printer<char_t, char_traits_t, std::list<value_t>> {
469 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::list<value_t>& values) {
470 __print_sequence_container(os, values.begin(), values.end());
471 }
472};
473
474template <typename char_t, typename char_traits_t, typename value_t>
475struct __tunit_value_printer<char_t, char_traits_t, std::initializer_list<value_t>> {
476 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::initializer_list<value_t>& values) {
477 __print_sequence_container(os, values.begin(), values.end());
478 }
479};
480
481template <typename char_t, typename char_traits_t, typename value_t>
482struct __tunit_value_printer<char_t, char_traits_t, std::vector<value_t>> {
483 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::vector<value_t>& values) {
484 __print_sequence_container(os, values.begin(), values.end());
485 }
486};
487
488template <typename char_t, typename char_traits_t, typename Iterator>
489std::basic_ostream<char_t, char_traits_t>& __print_associative_container(std::basic_ostream<char_t, char_traits_t>& os, const Iterator& begin, const Iterator& end) {
490 os << "{";
491 bool first = true;
492 for (Iterator it = begin; it != end; ++it) {
493 if (!first) os << ", ";
494 __tunit_value_printer<char_t, char_traits_t, typename std::iterator_traits<Iterator>::value_type>::print(os, *it);
495 first = false;
496 }
497 return os << "}";
498}
499
500template <typename char_t, typename char_traits_t, typename Key, typename value_t>
501struct __tunit_value_printer<char_t, char_traits_t, std::map<Key, value_t>> {
502 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::map<Key, value_t>& values) {
503 __print_associative_container(os, values.begin(), values.end());
504 }
505};
506
507template <typename char_t, typename char_traits_t, typename Key, typename value_t>
508struct __tunit_value_printer<char_t, char_traits_t, std::multimap<Key, value_t>> {
509 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::multimap<Key, value_t>& values) {
510 __print_associative_container(os, values.begin(), values.end());
511 }
512};
513
514template <typename char_t, typename char_traits_t, typename value_t>
515struct __tunit_value_printer<char_t, char_traits_t, std::multiset<value_t>> {
516 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::multiset<value_t>& values) {
517 __print_associative_container(os, values.begin(), values.end());
518 }
519};
520
521template <typename char_t, typename char_traits_t, typename value_t>
522struct __tunit_value_printer<char_t, char_traits_t, std::set<value_t>> {
523 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::set<value_t>& values) {
524 __print_associative_container(os, values.begin(), values.end());
525 }
526};
527
528template <typename char_t, typename char_traits_t, typename Key, typename value_t>
529struct __tunit_value_printer<char_t, char_traits_t, std::unordered_map<Key, value_t>> {
530 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::unordered_map<Key, value_t>& values) {
531 __print_associative_container(os, values.begin(), values.end());
532 }
533};
534
535template <typename char_t, typename char_traits_t, typename Key, typename value_t>
536struct __tunit_value_printer<char_t, char_traits_t, std::unordered_multimap<Key, value_t>> {
537 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::unordered_multimap<Key, value_t>& values) {
538 __print_associative_container(os, values.begin(), values.end());
539 }
540};
541
542template <typename char_t, typename char_traits_t, typename value_t>
543struct __tunit_value_printer<char_t, char_traits_t, std::unordered_multiset<value_t>> {
544 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::unordered_multiset<value_t>& values) {
545 __print_associative_container(os, values.begin(), values.end());
546 }
547};
548
549template <typename char_t, typename char_traits_t, typename value_t>
550struct __tunit_value_printer<char_t, char_traits_t, std::unordered_set<value_t>> {
551 static void print(std::basic_ostream<char_t, char_traits_t>& os, const std::unordered_set<value_t>& values) {
552 __print_associative_container(os, values.begin(), values.end());
553 }
554};
555
556template <typename char_t, typename char_traits_t, typename type_t>
557std::basic_ostream<char_t, char_traits_t>& operator<<(std::basic_ostream<char_t, char_traits_t>& os, const type_t& value) {
558 __tunit_value_printer<char_t, char_traits_t, type_t>::print(os, value);
559 return os;
560}
561
562template <typename char_t, typename char_traits_t, typename type_t>
563std::basic_ostream<char_t, char_traits_t>& operator<<(std::basic_ostream<char_t, char_traits_t>& os, const type_t* value) {
564 __tunit_value_printer<char_t, char_traits_t, type_t>::print(os, value);
565 return os;
566}
567
568template <typename char_t, typename char_traits_t, typename type_t>
569std::basic_ostream<char_t, char_traits_t>& operator<<(std::basic_ostream<char_t, char_traits_t>& os, type_t* value) {
570 __tunit_value_printer<char_t, char_traits_t, type_t>::print(os, value);
571 return os;
572}
573
574inline std::string __tunit_codepoint_to_string(char32_t codepoint) {
575 std::string result;
576 if (codepoint < 0x80) {
577 result.push_back(static_cast<char>(codepoint));
578 } else if (codepoint < 0x800) {
579 result.push_back(static_cast<char>((codepoint >> 6) | 0xc0));
580 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
581 } else if (codepoint < 0x10000) {
582 result.push_back(static_cast<char>((codepoint >> 12) | 0xe0));
583 result.push_back(static_cast<char>(((codepoint >> 6) & 0x3f) | 0x80));
584 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
585 } else {
586 result.push_back(static_cast<char>((codepoint >> 18) | 0xf0));
587 result.push_back(static_cast<char>(((codepoint >> 12) & 0x3f) | 0x80));
588 result.push_back(static_cast<char>(((codepoint >> 6) & 0x3f) | 0x80));
589 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
590 }
591 return result;
592}
593
594inline std::string __tunit_to_string(const char8_t& value) {
595 std::stringstream ss;
596 ss << "\"" << __tunit_codepoint_to_string(value) << "\"";
597 return ss.str();
598}
599
600inline std::string __tunit_to_string(const char16_t& value) {
601 std::stringstream ss;
602 ss << "\"" << __tunit_codepoint_to_string(value) << "\"";
603 return ss.str();
604}
605
606inline std::string __tunit_to_string(const char32_t& value) {
607 std::stringstream ss;
608 ss << "\"" << __tunit_codepoint_to_string(value) << "\"";
609 return ss.str();
610}
611
612inline std::string __tunit_to_string(const wchar_t& value) {
613 std::stringstream ss;
614 ss << "\"" << __tunit_codepoint_to_string(value) << "\"";
615 return ss.str();
616}
617
618inline std::string __tunit_to_string(const std::string& value) {
619 std::stringstream ss;
620 ss << "\"" << value << "\"";
621 return ss.str();
622}
623
624inline std::string __tunit_to_string(const xtd::ustring& value) {
625 std::stringstream ss;
626 ss << "\"" << value << "\"";
627 return ss.str();
628}
629
630inline std::string __tunit_to_string(const std::u8string& value) {
631 std::stringstream ss;
632 ss << "\"" << value << "\"";
633 return ss.str();
634}
635
636inline std::string __tunit_to_string(const std::u16string& value) {
637 std::string result;
638 result += "\"";
639 for (auto codepoint : value)
640 result += __tunit_codepoint_to_string(codepoint);
641 result += "\"";
642 return result;
643}
644
645inline std::string __tunit_to_string(const std::u32string& value) {
646 std::string result;
647 result += "\"";
648 for (auto codepoint : value)
649 result += __tunit_codepoint_to_string(codepoint);
650 result += "\"";
651 return result;
652}
653
654inline std::string __tunit_to_string(const std::wstring& value) {
655 std::string result;
656 result += "\"";
657 for (auto codepoint : value)
658 result += __tunit_codepoint_to_string(codepoint);
659 result += "\"";
660 return result;
661}
662
663inline std::string __tunit_to_string(const char* value) {
664 std::stringstream ss;
665 ss << "\"" << value << "\"";
666 return ss.str();
667}
668
669inline std::string __tunit_to_string(const char8_t* value) {
670 return __tunit_to_string(std::u8string(value));
671}
672
673inline std::string __tunit_to_string(const char16_t* value) {
674 return __tunit_to_string(std::u16string(value));
675}
676
677inline std::string __tunit_to_string(const char32_t* value) {
678 return __tunit_to_string(std::u32string(value));
679}
680
681inline std::string __tunit_to_string(const wchar_t* value) {
682 return __tunit_to_string(std::wstring(value));
683}
684
685template <typename value_t>
686inline std::string __tunit_to_string(const value_t& value) {
687 std::stringstream ss;
688 ss << value;
689 return ss.str();
690}
691
692template <typename value_t>
693inline std::string __tunit_to_string(const value_t* value) {
694 std::stringstream ss;
695 ss << value;
696 return ss.str();
697}
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:48
size_t size
Represents a size of any object in bytes.
Definition types.h:171
@ end
The END key.
@ print
The PRINT key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::ustring class.