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