before this change, format_as() is unable to format a type which
has `auto format_as() -> const another_type&`, and `another_type`
is formattable. because `format_as_result` maps the result type
as it is, and the compiler refuses to compile
`static_cast<T*>(nullptr)`, where T is a reference type. but
it would be handy if we could use `format_as()` to format types
which, for instance, owns / inherit from a formattable type, and
delegate the formatter to these variables instead without creating
a copy of them.
in this change:
* instruct `format_as_result` to map the
result type to the decayed type, so that `type` can be the decayed
type of result type, and this also enables `type` to be formattable,
as long as the decayed type is formattable.
* corresponding test is added to format-test.cc
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
This adds support for `%j` presentation type for duration types:
> "If the type being formatted is a specialization of duration, the decimal
number of days without padding."
Fixes#3643.
* Fix#3725 and rename fmt_safe_duration_cast to fmt_duration_cast
The function is now more generic and will handle all casts. It also
takes care of toggling safe vs unsafe casts using
FMT_SAFE_DURATION_CAST.
* Refactor fmt_duration_cast to put #ifdef inside the function
* Fix compilation error with FMT_USE_LOCAL_TIME
Formatting a std::optional<T> where T had a custom format_as(T) function failed to compile with clang,
due to set_debug_format being hidden by private inheritance. This fix makes the function available through a using clause.
* Namespace-qualify to avoid ambiguity with std::format_to for format-test.cc
When build fmt with MSVC under option /std:c++latest, it failed due to `error 2668: 'std::format_to': ambiguous call to overloaded function`, so add namespace to qualify the call to format_to to avoid this issue.
* fix: make std::bitset formattable again
It used to be formattable via operator<<(ostream&) implicitly. Make it
formattable again, but this time via formatter specialization.
* fix: make nested_formatter constexpr default constructible
* Avoid a space in the UDL definition except on GCC before 4.9
Clang 18 has grown a warning about the space being deprecated which
is enabled by default in their nightly binaries. However GCC before 4.9
will reject the UDL definition unless there is a space there, so we need
to keep the space conditionally for it.
* Remove UDLs on GCC before 4.9 to simplify things
GCC before 4.9 rejects the syntax that is now
rejected on more modern compilers.
* Disable compile-error-test on GCC < 4.9
This avoids the UDL tests failing as GCC < 4.9 can not parse UDLs
without a space, but the space is malformed in modern compilers.
With this, fmt can be used on Windows 98 and the Original Xbox with:
set(FMT_OS OFF)
It is not exposed as a CMake option but one can define it manually
in the fmt subproject, e.g.:
target_compile_definitions(fmt PUBLIC FMT_WINDOWS_NO_WCHAR)
Fixes#3631