MCPcopy Create free account
hub / github.com/bupticybee/TexasSolver / formatValue

Function formatValue

include/tools/tinyformat.h:336–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334/// conversions.
335template<typename T>
336inline void formatValue(std::ostream& out, const char* /*fmtBegin*/,
337 const char* fmtEnd, int ntrunc, const T& value)
338{
339#ifndef TINYFORMAT_ALLOW_WCHAR_STRINGS
340 // Since we don't support printing of wchar_t using "%ls", make it fail at
341 // compile time in preference to printing as a void* at runtime.
342 typedef typename detail::is_wchar<T>::tinyformat_wchar_is_not_supported DummyType;
343 (void) DummyType(); // avoid unused type warning with gcc-4.8
344#endif
345 // The mess here is to support the %c and %p conversions: if these
346 // conversions are active we try to convert the type to a char or const
347 // void* respectively and format that instead of the value itself. For the
348 // %p conversion it's important to avoid dereferencing the pointer, which
349 // could otherwise lead to a crash when printing a dangling (const char*).
350 const bool canConvertToChar = detail::is_convertible<T,char>::value;
351 const bool canConvertToVoidPtr = detail::is_convertible<T, const void*>::value;
352 detail::spaceFillIfNotFinite(out, value);
353 if (canConvertToChar && *(fmtEnd-1) == 'c')
354 detail::formatValueAsType<T, char>::invoke(out, value);
355 else if (canConvertToVoidPtr && *(fmtEnd-1) == 'p')
356 detail::formatValueAsType<T, const void*>::invoke(out, value);
357#ifdef TINYFORMAT_OLD_LIBSTDCPLUSPLUS_WORKAROUND
358 else if (detail::formatZeroIntegerWorkaround<T>::invoke(out, value)) /**/;
359#endif
360 else if (ntrunc >= 0) {
361 // Take care not to overread C strings in truncating conversions like
362 // "%.4s" where at most 4 characters may be read.
363 detail::formatTruncated(out, value, ntrunc);
364 }
365 else
366 out << value;
367}
368
369
370// Overloaded version for char types to support printing as an integer

Callers

nothing calls this directly

Calls 2

spaceFillIfNotFiniteFunction · 0.85
formatTruncatedFunction · 0.85

Tested by

no test coverage detected