iutest  1.17.99.14
iutest_printers.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_PRINTERS_HPP_A6A321C9_9279_4336_8167_058C59EC0FD0_
16 #define INCG_IRIS_IUTEST_PRINTERS_HPP_A6A321C9_9279_4336_8167_058C59EC0FD0_
17 
18 //======================================================================
19 // include
20 // IWYU pragma: begin_exports
21 #include "iutest_defs.hpp"
24 // IWYU pragma: end_exports
25 
26 #if IUTEST_USE_QUADMATH
27 # include <quadmath.h>
28 #endif
29 
30 
31 namespace iutest
32 {
33 
34 // PrintTo (User defined)
35 // PrintTo (iutest)
36 // DefaultPrintTo
37 // container
38 // pointer
39 // ostream operator <<
40 // BiggestInt
41 // bytes
42 
43 //======================================================================
44 // declare
45 template<typename T>
46 std::string PrintToString(const T& v);
47 
48 namespace detail
49 {
50 
51 template<typename T>
52 void UniversalPrint(const T& value, iu_ostream* os);
53 
54 inline void PrintBytesInObjectTo(const unsigned char* buf, size_t size, iu_ostream* os)
55 {
56 IUTEST_PRAGMA_CONSTEXPR_CALLED_AT_RUNTIME_WARN_DISABLE_BEGIN()
57  const size_t kMaxCount = detail::kValues::MaxPrintContainerCount;
58  *os << size << "-Byte object < ";
59  if( buf != IUTEST_NULLPTR && size > 0 )
60  {
61  for( size_t i=0; i < size; ++i )
62  {
63  if( i == kMaxCount )
64  {
65  *os << "... ";
66  break;
67  }
68 #ifdef __clang_analyzer__
69  const unsigned char n = 0; // suppress
70 #else
71  const unsigned char n = buf[i];
72 #endif
73  *os << ToHex((n>>4)&0xF) << ToHex(n&0xF) << " ";
74  }
75  }
76  *os << ">";
77 IUTEST_PRAGMA_CONSTEXPR_CALLED_AT_RUNTIME_WARN_DISABLE_END()
78 }
79 
80 namespace printer_internal
81 {
82 
83 namespace formatter
84 {
85 
86 struct RawBytesPrinter
87 {
88  template<typename T>
89  static void Print(const T& value, iu_ostream* os)
90  {
91  const unsigned char* ptr = const_cast<const unsigned char*>(
92  reinterpret_cast<const volatile unsigned char*>(&value));
93  const size_t size = sizeof(T);
94  PrintBytesInObjectTo(ptr, size, os);
95  }
96 };
97 
98 struct StringViewPrinter
99 {
100  static void Print(iu_string_view value, iu_ostream* os)
101  {
102  UniversalPrint(value, os);
103  }
104 };
105 
106 struct BiggestIntPrinter
107 {
108  static void Print(BiggestInt value, iu_ostream* os)
109  {
110 #if IUTEST_HAS_BIGGESTINT_OSTREAM
111  *os << value;
112 #else
113  const Int32 v = value;
114  *os << v;
115 #endif
116  }
117 };
118 
120 template<typename T>
121 struct PrinterTypeSelecter
122 {
123  typedef typename iutest_type_traits::conditional<iutest_type_traits::is_convertible<T, BiggestInt>::value
124  , BiggestIntPrinter
125  , typename iutest_type_traits::conditional<iutest_type_traits::is_convertible<T, iu_string_view>::value
126  , StringViewPrinter
127  , RawBytesPrinter
128  >::type
129  >::type type;
130 };
131 
132 } // end of namespace formatter
133 
135 class TypeWithoutFormatter
136 {
137 public:
138  template<typename T>
139  static void PrintValue(const T& value, iu_ostream* os)
140  {
141  typedef typename formatter::PrinterTypeSelecter<const T&>::type Printer;
142  Printer::Print(value, os);
143  }
144 };
145 
146 #if !defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP)
147 
148 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
149 template<typename Elem, typename Traits, typename T>
150 ::std::basic_ostream<Elem, Traits>& operator << (::std::basic_ostream<Elem, Traits>& os, const T& value)
151 {
152  TypeWithoutFormatter::PrintValue(value, &os);
153  return os;
154 }
155 #else
156 template<typename Elem, typename Traits, typename T>
157 detail::iu_basic_ostream<Elem, Traits>& operator << (detail::iu_basic_ostream<Elem, Traits>& os, const T& value)
158 {
159  TypeWithoutFormatter::PrintValue(value, &os);
160  return os;
161 }
162 #endif
163 
164 #endif
165 
166 } // end of namespace printer_internal
167 
168 namespace printer_internal2
169 {
170 
171 // 解決順序
172 // foo::operator <<
173 // ::operator <<
174 // ::iutest::detail::printer_internal::operator <<
175 template<typename T>
176 void DefaultPrintNonContainerTo(const T& value, iu_ostream* os)
177 {
178  using namespace ::iutest::detail::printer_internal; // NOLINT
179  *os << value;
180 }
181 
182 } // end of namespace printer_internal2
183 
184 //======================================================================
185 // declare
186 
187 //======================================================================
188 // function
192 template<typename T>
193 inline void DefaultPrintTo(IsContainerHelper::yes_t
194  , iutest_type_traits::false_type
195  , const T& container, iu_ostream* os)
196 {
197  const size_t kMaxCount = kValues::MaxPrintContainerCount;
198  size_t count = 0;
199  *os << "{";
200  for( typename T::const_iterator it=container.begin(), end=container.end(); it != end; ++it, ++count)
201  {
202  if( count > 0 )
203  {
204  *os << ",";
205  if( count == kMaxCount )
206  {
207  *os << " ...";
208  break;
209  }
210  }
211  *os << " ";
212  UniversalPrint(*it, os);
213  }
214  if( count > 0 )
215  {
216  *os << " ";
217  }
218  *os << "}";
219 }
220 
221 template<typename T>
222 inline void DefaultPrintNonContainerTo(const T& value, iu_ostream* os)
223 {
224 #if !defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP)
225  printer_internal2::DefaultPrintNonContainerTo(value, os);
226 #else
227  printer_internal::formatter::RawBytesPrinter::Print(value, os);
228 #endif
229 }
231 template<typename T>
232 inline void DefaultPrintTo(IsContainerHelper::no_t
233  , iutest_type_traits::false_type
234  , const T& value, iu_ostream* os)
235 {
236  DefaultPrintNonContainerTo(value, os);
237 }
238 
239 #if !defined(IUTEST_NO_SFINAE) && !defined(IUTEST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
240 
241 template<typename T>
242 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os
243  , typename iutest_type_traits::enable_if_t< iutest_type_traits::is_convertible<T*, const void*> >::type*& = iutest_type_traits::enabler::value)
244 {
245  *os << reinterpret_cast<iu_uintptr_t>(ptr);
246 }
247 template<typename T>
248 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os
249  , typename iutest_type_traits::disable_if_t< iutest_type_traits::is_convertible<T*, const void*> >::type*& = iutest_type_traits::enabler::value)
250 {
251  *os << reinterpret_cast<const void*>(reinterpret_cast<type_least_t<8>::UInt>(ptr));
252 }
253 
254 #else
255 
256 template<typename T>
257 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os)
258 {
259  *os << reinterpret_cast<const void*>(reinterpret_cast<type_least_t<8>::UInt>(ptr));
260 }
261 
262 #endif
263 
264 template<typename T>
265 inline void DefaultPrintTo(IsContainerHelper::no_t
266  , iutest_type_traits::true_type
267  , T* ptr, iu_ostream* os)
268 {
269  if( ptr == IUTEST_NULLPTR )
270  {
271  *os << kStrings::Null;
272  }
273  else
274  {
275  DefaultPtrPrintTo<T>(ptr, os);
276  }
277 }
278 
279 
281 template<typename T>
282 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const T& value, iu_ostream* os)
283 {
284  UniversalPrint(value, os);
285 }
286 
287 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const char* str, iu_ostream* os)
288 {
289  if( str == IUTEST_NULLPTR )
290  {
291  *os << kStrings::Null;
292  }
293  else
294  {
295  UniversalPrint(::std::string(str), os);
296  }
297 }
298 template<size_t N>
299 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const char(&str)[N], iu_ostream* os)
300 {
301  return UniversalTersePrint(static_cast<const char*>(str), os);
302 }
303 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const wchar_t* str, iu_ostream* os)
304 {
305  UniversalPrint(detail::ShowAnyCString(str), os);
306 }
307 template<size_t N>
308 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const wchar_t(&str)[N], iu_ostream* os)
309 {
310  UniversalPrint(detail::ShowAnyCString(str), os);
311 }
312 #if IUTEST_HAS_CHAR16_T
313 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const char16_t* str, iu_ostream* os)
314 {
315  UniversalPrint(detail::ShowAnyCString(str), os);
316 }
317 template<size_t N>
318 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const char16_t(&str)[N], iu_ostream* os)
319 {
320  UniversalPrint(detail::ShowAnyCString(str), os);
321 }
322 #endif
323 #if IUTEST_HAS_CHAR32_T && (IUTEST_HAS_CXX_HDR_CUCHAR || IUTEST_HAS_CXX_HDR_CODECVT)
324 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const char32_t* str, iu_ostream* os)
325 {
326  UniversalPrint(detail::ShowAnyCString(str), os);
327 }
328 template<size_t N>
329 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(const char32_t(&str)[N], iu_ostream* os)
330 {
331  UniversalPrint(detail::ShowAnyCString(str), os);
332 }
333 #endif
334 
338 template<typename T>
339 inline void PrintTo(const T& value, iu_ostream* os) {
340  DefaultPrintTo(
341 #if !defined(IUTEST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)
342  IsContainerHelper::IsContainer<T>(0)
343 #else
344  IsContainerHelper::IsContainer(0, detail::explicit_type<T>())
345 #endif
346  , iutest_type_traits::is_pointer<T>(), value, os);
347 }
348 inline void PrintTo(bool b, iu_ostream* os) { *os << (b ? "true" : "false"); }
349 inline void PrintTo(const char* c, iu_ostream* os) { *os << c; }
350 #if defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP)
351 inline void PrintTo(int v, iu_ostream* os) { *os << v; }
352 #endif
353 inline void PrintTo(const ::std::string& str, iu_ostream* os) { *os << str.c_str(); }
354 template<typename CharT, typename Traits, typename Alloc>
355 inline void PrintTo(const ::std::basic_string<CharT, Traits, Alloc>& str, iu_ostream* os) { UniversalTersePrint(str.c_str(), os); }
356 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
357 template<typename T>
358 inline void PrintToFloatingPoint(const floating_point<T>& f, iu_ostream* os)
359 {
360  iu_stringstream ss;
361 #if IUTEST_HAS_IOMANIP
362  ss << ::std::setprecision(::std::numeric_limits<T>::digits10 + 2);
363 #endif
364  UniversalPrint(f.raw(), &ss);
365  *os << ss.str() << "(0x" << ToHexString(f.bits()) << ")";
366 }
367 template<typename T>
368 inline void PrintTo(const floating_point<T>& f, iu_ostream* os)
369 {
370  PrintToFloatingPoint(f, os);
371 }
372 template<typename T>
373 inline void PrintTo(const internal::FloatingPoint<T>& f, iu_ostream* os)
374 {
375  PrintToFloatingPoint(f, os);
376 }
377 template<typename T1, typename T2>
378 inline void PrintTo(const ::std::pair<T1, T2>& value, iu_ostream* os)
379 {
380  *os << "(";
381  UniversalPrint(value.first, os);
382  *os << ", ";
383  UniversalPrint(value.second, os);
384  *os << ")";
385 }
386 #endif
387 
388 #if IUTEST_HAS_INT128
389 inline void PrintTo(detail::type_fit_t<16>::Int v, iu_ostream* os)
390 {
391  *os << "0x" << ToHexString(v);
392 }
393 inline void PrintTo(detail::type_fit_t<16>::UInt v, iu_ostream* os)
394 {
395  *os << "0x" << ToHexString(v);
396 }
397 #endif
398 
399 #if IUTEST_HAS_FLOAT128
400 template<typename T>
401 inline void PrintToFloat128(const T v, iu_ostream* os)
402 {
403 #if IUTEST_USE_QUADMATH
404  char buf[256] = {0};
405  quadmath_snprintf(buf, sizeof(buf), "%Qf", v);
406  *os << buf;
407 #elif IUTEST_HAS_LONG_DOUBLE && IUTEST_LONG_DOUBLE_AS_IS_DOUBLE
408  *os << static_cast<long double>(v);
409 #else
410  *os << static_cast<double>(v);
411 #endif
412 }
413 
414 // NOTE: need libquadmath
415 inline void PrintTo(const internal::Float128::Float v, iu_ostream* os)
416 {
417  PrintToFloat128(v, os);
418 }
419 
420 #if IUTEST_HAS_LONG_DOUBLE && !IUTEST_LONG_DOUBLE_AS_IS_DOUBLE
421 inline void PrintTo(const long double v, iu_ostream* os)
422 {
423  PrintToFloat128(v, os);
424 }
425 #endif
426 
427 #endif
428 
429 template<typename T>
430 void PrintToChar(const T value, iu_ostream* os)
431 {
432  // char or unsigned char の時に、 0 が NULL 文字にならないように修正
433  if( value == 0 )
434  {
435  *os << "\\0";
436  }
437  else if( static_cast<int>(value) < 0x20 )
438  {
439  *os << "0x" << ToHexString(value);
440  }
441  else
442  {
443  const T str[2] = { value, 0 };
444  *os << "\'" << detail::ShowAnyCString(str) << "\'";
445  }
446 }
447 inline void PrintTo(const char value, iu_ostream* os)
448 {
449  PrintToChar(static_cast<signed char>(value), os);
450 }
451 inline void PrintTo(const wchar_t value, iu_ostream* os)
452 {
453  PrintToChar(value, os);
454 }
455 #if IUTEST_HAS_CHAR16_T
456 inline void PrintTo(const char16_t value, iu_ostream* os)
457 {
458  PrintToChar(value, os);
459 }
460 #endif
461 #if IUTEST_HAS_CHAR32_T
462 inline void PrintTo(const char32_t value, iu_ostream* os)
463 {
464  PrintToChar(value, os);
465 }
466 #endif
467 inline void PrintTo(const unsigned char value, iu_ostream* os)
468 {
469  *os << static_cast<unsigned int>(value);
470 }
471 #if IUTEST_USE_OWN_STRING_VIEW
472 template<typename CharT, typename Traits>
473 inline void PrintTo(const iu_basic_string_view<CharT, Traits>& value, iu_ostream* os)
474 {
475  const ::std::basic_string<CharT, Traits> str = value.data();
476  UniversalTersePrint(str.c_str(), os);
477 }
478 #else
479 template<typename CharT, typename Traits>
480 inline void PrintTo(const ::std::basic_string_view<CharT, Traits>& value, iu_ostream* os)
481 {
482  const ::std::basic_string<CharT, Traits> str{ value };
483  UniversalTersePrint(str.c_str(), os);
484 }
485 #endif
486 
487 #if IUTEST_HAS_CXX_HDR_OPTIONAL
488 template<typename T>
489 inline void PrintTo(const ::std::optional<T>& value, iu_ostream* os)
490 {
491  if (value)
492  {
493  UniversalPrint(value.value(), os);
494  }
495  else
496  {
497  *os << "nullopt";
498  }
499 }
500 #endif
501 
502 #if IUTEST_HAS_VARIADIC_TEMPLATES && IUTEST_HAS_CXX_HDR_VARIANT
503 template<typename... Types>
504 inline void PrintTo(const ::std::variant<Types...>& value, iu_ostream* os)
505 {
506  if (value.valueless_by_exception())
507  {
508  *os << "valueless_by_exception";
509  }
510  else
511  {
512  ::std::visit([&os](const auto& v) { UniversalPrint(v, os); }, value);
513  }
514 }
515 inline void PrintTo(const ::std::monostate&, iu_ostream* os)
516 {
517  *os << "monostate";
518 }
519 #endif
520 
521 #if IUTEST_HAS_CXX_HDR_ANY
522 inline void PrintTo(const ::std::any& value, iu_ostream* os)
523 {
524  *os << "-Any type-name: " << value.type().name();
525  DefaultPrintNonContainerTo(value, os);
526 }
527 #endif
528 
529 #if IUTEST_HAS_STD_FILESYSTEM
530 inline ::std::string FileSystemFileTypeToString(const ::std::filesystem::file_type& value)
531 {
532  switch(value)
533  {
534  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, none);
535  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, not_found);
536  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, regular);
537  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, directory);
538  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, symlink);
539  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, block);
540  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, character);
541  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, fifo);
542  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, socket);
543  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, unknown);
544 #if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_MINGW)
545  IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, junction);
546 #endif
547  }
548  return PrintToString(static_cast<int>(value));
549 }
550 template<>
551 inline void PrintTo< ::std::filesystem::path >(const ::std::filesystem::path& value, iu_ostream* os)
552 {
553  *os << value.generic_string();
554 }
555 inline void PrintTo(const ::std::filesystem::file_type& value, iu_ostream* os)
556 {
557  *os << FileSystemFileTypeToString(value);
558 }
559 inline void PrintTo(const ::std::filesystem::perms& value, iu_ostream* os)
560 {
561  *os << ToOctString(static_cast<UInt16>(value));
562 }
563 inline void PrintTo(const ::std::filesystem::file_status& value, iu_ostream* os)
564 {
565  *os << FileSystemFileTypeToString(value.type()) << ": ";
566  PrintTo(value.permissions(), os);
567 }
568 inline void PrintTo(const ::std::filesystem::space_info& value, iu_ostream* os)
569 {
570  *os << "cpacity: " << detail::FormatSizeByte(value.capacity)
571  << ", free: " << detail::FormatSizeByte(value.free)
572  << ", available: " << detail::FormatSizeByte(value.available);
573 }
574 inline void PrintTo(const ::std::filesystem::directory_entry& value, iu_ostream* os)
575 {
576  PrintTo(value.path(), os);
577 }
578 inline void PrintTo(const ::std::filesystem::directory_iterator& value, iu_ostream* os)
579 {
580  PrintTo(*value, os);
581 }
582 #endif
583 
584 #if IUTEST_HAS_NULLPTR
585 inline void PrintTo(const ::std::nullptr_t&, iu_ostream* os) { *os << "nullptr"; }
586 #endif
587 
588 #if IUTEST_HAS_TUPLE
589 
590 template<typename T, int I, int SIZE>
591 inline void PrintTupleElemTo(const T& t, iu_ostream* os
592  , typename iutest_type_traits::enable_if<I == 0, void>::type*& = iutest_type_traits::enabler::value)
593 {
594  IUTEST_UNUSED_VAR(t);
595  IUTEST_UNUSED_VAR(os);
596 }
597 template<typename T, int I, int SIZE>
598 inline void PrintTupleElemTo(const T& t, iu_ostream* os
599  , typename iutest_type_traits::enable_if<I == 1, void>::type*& = iutest_type_traits::enabler::value)
600 {
601  PrintTo(tuples::get<SIZE-I>(t), os);
602 }
603 template<typename T, int I, int SIZE>
604 inline void PrintTupleElemTo(const T& t, iu_ostream* os
605  , typename iutest_type_traits::enable_if<(I&(~1)) != 0, void>::type*& = iutest_type_traits::enabler::value)
606 {
607  PrintTo(tuples::get<SIZE-I>(t), os);
608  *os << ", ";
609  PrintTupleElemTo<T, I-1, SIZE>(t, os);
610 }
611 
612 template<typename T>
613 inline void PrintTupleTo(const T& t, iu_ostream* os)
614 {
615  *os << "(";
616  PrintTupleElemTo<T, tuples::tuple_size<T>::value, tuples::tuple_size<T>::value>(t, os);
617  *os << ")";
618 }
619 
620 #if IUTEST_HAS_VARIADIC_TEMPLATES && IUTEST_HAS_TUPLE
621 
622 template<typename ...Args>
623 inline void PrintTo(const tuples::tuple<Args...>& t, iu_ostream* os)
624 {
625  PrintTupleTo(t, os);
626 }
627 
628 #else
629 
630 #define IIUT_DECL_TUPLE_PRINTTO(n) \
631  template<IUTEST_PP_ENUM_PARAMS(n, typename A)>inline void PrintTo( \
632  const tuples::tuple<IUTEST_PP_ENUM_PARAMS(n, A)>& t, iu_ostream* os) { \
633  PrintTupleTo(t, os); }
634 
635 inline void PrintTo(const tuples::tuple<>& t, iu_ostream* os) { PrintTupleTo(t, os); }
636 
637 IIUT_DECL_TUPLE_PRINTTO(1)
638 IIUT_DECL_TUPLE_PRINTTO(2)
639 IIUT_DECL_TUPLE_PRINTTO(3)
640 IIUT_DECL_TUPLE_PRINTTO(4)
641 IIUT_DECL_TUPLE_PRINTTO(5)
642 IIUT_DECL_TUPLE_PRINTTO(6)
643 IIUT_DECL_TUPLE_PRINTTO(7)
644 IIUT_DECL_TUPLE_PRINTTO(8)
645 IIUT_DECL_TUPLE_PRINTTO(9)
646 
647 #undef IIUT_DECL_TUPLE_PRINTTO
648 
649 #endif
650 
651 #endif
652 
656 template<typename T>
657 inline void PrintRawArrayTo(const T* a, size_t cnt, iu_ostream* os)
658 {
659  UniversalPrint<T>(a[0], os);
660  for( size_t i=1; i < cnt; ++i )
661  {
662  *os << ", ";
663  UniversalPrint<T>(a[i], os);
664  }
665 }
666 
670 template<typename T>
671 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(const T* begin, size_t N, iu_ostream* os)
672 {
673  if( N == 0 )
674  {
675  *os << "{}";
676  }
677  else
678  {
679  *os << "{ ";
680  const size_t kThreshold = kValues::PrintArrayThreshold;
681  const size_t kChunksize = kValues::PrintArrayChunksize;
682  if( N <= kThreshold )
683  {
684  PrintRawArrayTo(begin, N, os);
685  }
686  else
687  {
688  PrintRawArrayTo(begin, kChunksize, os);
689  *os << ", ..., ";
690  PrintRawArrayTo(begin + N - kChunksize, kChunksize, os);
691  }
692  *os << " }";
693  }
694 }
698 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(const char* begin, size_t N, iu_ostream* os)
699 {
700  IUTEST_UNUSED_VAR(N);
701  UniversalTersePrint(begin, os);
702 }
703 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(const wchar_t* begin, size_t N, iu_ostream* os)
704 {
705  IUTEST_UNUSED_VAR(N);
706  UniversalTersePrint(begin, os);
707 }
708 
710 template<typename T>
711 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintTo(const T& value, iu_ostream* os)
712 {
713  PrintTo(value, os);
714 }
715 
716 //======================================================================
717 // class
719 template<typename T>
720 class iuUniversalPrinter
721 {
722 public:
723  static void Print(const T& value, iu_ostream* os)
724  {
725  UniversalPrintTo(value, os);
726  }
727 };
728 
729 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
730 
732 template<typename T, size_t SIZE>
733 class iuUniversalPrinter<T[SIZE]>
734 {
735 public:
736  static void Print(const T(&a)[SIZE], iu_ostream* os)
737  {
738  UniversalPrintArray(a, SIZE, os);
739  }
740 };
741 
742 #endif
743 
744 //======================================================================
745 // function
747 template<typename T>
748 inline void UniversalPrint(const T& value, iu_ostream* os)
749 {
750 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
751  iuUniversalPrinter<T>::Print(value, os);
752 #else
753  UniversalPrintTo(value, os);
754 #endif
755 }
756 
757 } // end of namespace detail
758 
759 //======================================================================
760 // function
761 
765 template<typename T>
766 inline ::std::string PrintToString(const T& v)
767 {
769  detail::UniversalTersePrint(v, &strm);
770  return strm.str();
771 }
772 
773 #if IUTEST_HAS_VARIADIC_TEMPLATES
777 template<typename T>
778 inline ::std::string PrintToStrings(const char* separate, const T& v)
779 {
780  IUTEST_UNUSED_VAR(separate);
781  return PrintToString(v);
782 }
786 template<typename T, typename ...Args>
787 inline ::std::string PrintToStrings(const char* separate, const T& v, Args... args)
788 {
789  ::std::string str = PrintToString(v);
790  str += separate;
791  str += PrintToStrings(separate, args...);
792  return str;
793 }
794 #endif
795 
796 } // end of namespace iutest
797 
798 #endif // INCG_IRIS_IUTEST_PRINTERS_HPP_A6A321C9_9279_4336_8167_058C59EC0FD0_
テストベース
Definition: iutest_body.hpp:44
ostream_formatter オプションが適用されてた stringstream
Definition: iutest_env.hpp:843
iris unit test definition
iris unit test iu_basic_ostream implimentaion
iutest root namespace
Definition: iutest_charcode.hpp:33
std::string PrintToString(const T &v)
文字列化
Definition: iutest_printers.hpp:767
detail::type_fit_t< 4 >::Int Int32
32 bit 符号付き整数型
Definition: iutest_defs.hpp:502
inline ::std::string PrintToStrings(const char *separate, const T &v)
文字列化
Definition: iutest_printers.hpp:779
detail::type_least_t< 8 >::Int BiggestInt
Biggest Int
Definition: iutest_defs.hpp:527