9.0.0
版本发布时间: 2022-07-05 21:11:37
fmtlib/fmt最新发布版本:11.0.2(2024-07-20 22:32:04)
Switched to the internal floating point formatter for all decimal presentation formats. In particular this results in consistent rounding on all platforms and removing the s[n]printf
fallback for decimal FP formatting.
Compile-time floating point formatting no longer requires the header-only mode. For example (godbolt):
#include <array>
#include <fmt/compile.h>
consteval auto compile_time_dtoa(double value) -> std::array<char, 10> {
auto result = std::array<char, 10>();
fmt::format_to(result.data(), FMT_COMPILE("{}"), value);
return result;
}
constexpr auto answer = compile_time_dtoa(0.42);
works with the default settings.
Improved the implementation of Dragonbox, the algorithm used for the default floating-point formatting (#2713, #2750). Thanks @jk-jeon (Junekey Jeon).
Made fmt::to_string
work with __float128
. This uses the internal FP formatter and works even on system without __float128
support in [s]printf
.
Disabled automatic std::ostream
insertion operator (operator<<
) discovery when fmt/ostream.h
is included to prevent ODR violations. You can get the old behavior by defining FMT_DEPRECATED_OSTREAM
but this will be removed in the next major release. Use fmt::streamed
or fmt::ostream_formatter
to enable formatting via std::ostream
instead.
Added fmt::ostream_formatter
that can be used to write formatter
specializations that perform formatting via std::ostream
. For example (godbolt):
#include <fmt/ostream.h>
struct date {
int year, month, day;
friend std::ostream& operator<<(std::ostream& os, const date& d) {
return os << d.year << '-' << d.month << '-' << d.day;
}
};
template <> struct fmt::formatter<date> : ostream_formatter {};
std::string s = fmt::format("The date is {}", date{2012, 12, 9});
// s == "The date is 2012-12-9"
Added the fmt::streamed
function that takes an object and formats it via std::ostream
. For example (godbolt):
#include <thread>
#include <fmt/ostream.h>
int main() {
fmt::print("Current thread id: {}\n",
fmt::streamed(std::this_thread::get_id()));
}
Note that fmt/std.h
provides a formatter
specialization for std::thread::id
so you don't need to format it via std::ostream
.
Deprecated implicit conversions of unscoped enums to integers for consistency with scoped enums.
Added an argument-dependent lookup based format_as
extension API to simplify formatting of enums.
Added experimental std::variant
formatting support (#2941). For example (godbolt):
#include <variant>
#include <fmt/std.h>
int main() {
auto v = std::variant<int, std::string>(42);
fmt::print("{}\n", v);
}
prints:
variant(42)
Thanks @jehelset.
Added experimental std::filesystem::path
formatting support (#2865, #2902, #2917, #2918). For example (godbolt):
#include <filesystem>
#include <fmt/std.h>
int main() {
fmt::print("There is no place like {}.", std::filesystem::path("/home"));
}
prints:
There is no place like "/home".
Thanks @phprus (Vladislav Shchapov).
Added a std::thread::id
formatter to fmt/std.h
. For example (godbolt):
#include <thread>
#include <fmt/std.h>
int main() {
fmt::print("Current thread id: {}\n", std::this_thread::get_id());
}
Added fmt::styled
that applies a text style to an individual argument (#2793). For example (godbolt):
#include <fmt/chrono.h>
#include <fmt/color.h>
int main() {
auto now = std::chrono::system_clock::now();
fmt::print(
"[{}] {}: {}\n",
fmt::styled(now, fmt::emphasis::bold),
fmt::styled("error", fg(fmt::color::red)),
"something went wrong");
}
prints
Thanks @rbrugo (Riccardo Brugo).
Made fmt::print
overload for text styles correctly handle UTF-8 (#2681, #2701). Thanks @AlexGuteniev (Alex Guteniev).
Fixed Unicode handling when writing to an ostream.
Added support for nested specifiers to range formatting (#2673). For example (godbolt):
#include <vector>
#include <fmt/ranges.h>
int main() {
fmt::print("{::#x}\n", std::vector{10, 20, 30});
}
prints [0xa, 0x14, 0x1e]
.
Thanks @BRevzin (Barry Revzin).
Implemented escaping of wide strings in ranges (#2904). Thanks @phprus (Vladislav Shchapov).
Added support for ranges with begin
/ end
found via the argument-dependent lookup (#2807). Thanks @rbrugo (Riccardo Brugo).
Fixed formatting of certain kinds of ranges of ranges (#2787). Thanks @BRevzin (Barry Revzin).
Fixed handling of maps with element types other than std::pair
(#2944). Thanks @BrukerJWD (Jonathan W).
Made tuple formatter enabled only if elements are formattable (#2939, #2940). Thanks @jehelset.
Made fmt::join
compatible with format string compilation (#2719, #2720). Thanks @phprus (Vladislav Shchapov).
Made compile-time checks work with named arguments of custom types and std::ostream
print
overloads (#2816, #2817, #2819). Thanks @timsong-cpp.
Removed make_args_checked
because it is no longer needed for compile-time checks (#2760). Thanks @phprus (Vladislav Shchapov).
Removed the following deprecated APIs: _format
, arg_join
, the format_to
overload that takes a memory buffer, [v]fprintf
that takes an ostream
.
Removed the deprecated implicit conversion of [const] signed char*
and [const] unsigned char*
to C strings.
Removed the deprecated fmt/locale.h
.
Replaced the deprecated fileno()
with descriptor()
in buffered_file
.
Moved to_string_view
to the detail
namespace since it's an implementation detail.
Made access mode of a created file consistent with fopen
by setting S_IWGRP
and S_IWOTH
(#2733). Thanks @arogge (Andreas Rogge).
Removed a redundant buffer resize when formatting to std::ostream
(#2842, #2843). Thanks @jcelerier (Jean-Michaël Celerier).
Made precision computation for strings consistent with width (#2888).
Fixed handling of locale separators in floating point formatting (#2830).
Made sign specifiers work with __int128_t
(#2773).
Improved support for systems such as CHERI with extra data stored in pointers (#2932). Thanks @davidchisnall (David Chisnall).
Improved documentation (#2706, #2712, #2789, #2803, #2805, #2815, #2924). Thanks @BRevzin (Barry Revzin), @Pokechu22, @setoye (Alta), @rtobar, @rbrugo (Riccardo Brugo), @anoonD (cre), @leha-bot (Alex).
Improved build configuration (#2766, #2772, #2836, #2852, #2907, #2913, #2914). Thanks @kambala-decapitator (Andrey Filipenkov), @mattiasljungstrom (Mattias Ljungström), @kieselnb (Nick Kiesel), @nathannaveen, @Vertexwahn.
Fixed various warnings and compilation issues (#2408, #2507, #2697, #2715, #2717, #2722, #2724, #2725, #2726, #2728, #2732, #2738, #2742, #2744, #2745, #2746, #2754, #2755, #2757, #2758, #2761, #2762, #2763, #2765, #2769, #2770, #2771, #2777, #2779, #2782, #2783, #2794, #2796, #2797, #2801, #2802, #2808, #2818, #2819, #2829, #2835, #2848, #2860, #2861, #2882, #2886, #2891, #2892, #2895, #2896, #2903, #2906, #2908, #2909, #2920, #2922, #2927, #2929, #2936, #2937, #2938, #2951, #2954, #2957, #2958, #2960). Thanks @matrackif @Tobi823 (Tobias Hellmann), @ivan-volnov (Ivan Volnov), @VasiliPupkin256, @federico-busato (Federico), @barcharcraz (Charlie Barto), @jk-jeon (Junekey Jeon), @HazardyKnusperkeks (Björn Schäpers), @dalboris (Boris Dalstein), @seanm (Sean McBride), @gsjaardema (Greg Sjaardema), @timsong-cpp, @seanm (Sean McBride), @frithrah, @chronoxor (Ivan Shynkarenka), @Agga, @madmaxoft (Mattes D), @JurajX (Juraj), @phprus (Vladislav Shchapov), @Dani-Hub (Daniel Krügler).
Pull Requests
- Make colored print handle UTF-8 by @AlexGuteniev in https://github.com/fmtlib/fmt/pull/2701
- Supporting nested format specs for ranges. by @brevzin in https://github.com/fmtlib/fmt/pull/2673
- Adding comments for range formatting. by @brevzin in https://github.com/fmtlib/fmt/pull/2706
- Docs: Fix link to "Compile-time Format String Checks" section by @Pokechu22 in https://github.com/fmtlib/fmt/pull/2712
- fmt::join support FMT_COMPILE by @phprus in https://github.com/fmtlib/fmt/pull/2720
- Fix overflow for chrono durations by @matrackif in https://github.com/fmtlib/fmt/pull/2722
- Fix -Wconversion warning by @Tobi823 in https://github.com/fmtlib/fmt/pull/2724
- Fix codecvt warning (#2408) by @ivan-volnov in https://github.com/fmtlib/fmt/pull/2725
- Simplify Dragonbox by @jk-jeon in https://github.com/fmtlib/fmt/pull/2713
- Making target_compile_options PRIVATE, fix #2726, fix #2507 by @VasiliPupkin256 in https://github.com/fmtlib/fmt/pull/2728
- Fixes NVIDIA HPC compiler and Intel ICC compatibility by @federico-busato in https://github.com/fmtlib/fmt/pull/2732
- Fix access mode of files created (#2530) by @arogge in https://github.com/fmtlib/fmt/pull/2733
- Supporting ? as a string presentation type by @brevzin in https://github.com/fmtlib/fmt/pull/2674
- qualify unqualified calls to format in compile.h by @barcharcraz in https://github.com/fmtlib/fmt/pull/2742
- Add missing const qualifier by @phprus in https://github.com/fmtlib/fmt/pull/2755
- Workaround for Intel compiler by @phprus in https://github.com/fmtlib/fmt/pull/2758
- Reflect the new paper on Dragonbox by @jk-jeon in https://github.com/fmtlib/fmt/pull/2750
- Replace
make_args_checked
withmake_format_args
by @phprus in https://github.com/fmtlib/fmt/pull/2760 - Address Issue #2763 by @jk-jeon in https://github.com/fmtlib/fmt/pull/2765
- Update .bazelversion by @Vertexwahn in https://github.com/fmtlib/fmt/pull/2766
- Clz builtin may be not constexpr by @phprus in https://github.com/fmtlib/fmt/pull/2762
- Apply 2746 fix for NVidia compiler also by @gsjaardema in https://github.com/fmtlib/fmt/pull/2770
- add ability to build library as Apple framework by @kambala-decapitator in https://github.com/fmtlib/fmt/pull/2772
- Ignore clang
-Wliteral-range
warning by @phprus in https://github.com/fmtlib/fmt/pull/2779 - Fixing "C4127: conditional expression is constant" Visual Studio 2022 warning in pedantic mode by @chronoxor in https://github.com/fmtlib/fmt/pull/2783
- Fix Conversion by @HazardyKnusperkeks in https://github.com/fmtlib/fmt/pull/2782
- fix typo by @setoye in https://github.com/fmtlib/fmt/pull/2789
- Fixing formatting of certain kinds of ranges of ranges. by @brevzin in https://github.com/fmtlib/fmt/pull/2787
- Fix warning C4251: class fmt::v8::file needs to have dll-interface by @dalboris in https://github.com/fmtlib/fmt/pull/2797
- Eliminate intel compiler warnings by @gsjaardema in https://github.com/fmtlib/fmt/pull/2802
- Implement styled arguments by @rbrugo in https://github.com/fmtlib/fmt/pull/2793
- Document output_file default behavior correctly by @rtobar in https://github.com/fmtlib/fmt/pull/2803
- Add
styled
in documentation by @rbrugo in https://github.com/fmtlib/fmt/pull/2805 - Fix compilation error for ranges with ADL
begin
/end
by @rbrugo in https://github.com/fmtlib/fmt/pull/2807 - Update color.h by @anoonD in https://github.com/fmtlib/fmt/pull/2815
- Fixes for #2816/2817/2818 by @timsong-cpp in https://github.com/fmtlib/fmt/pull/2819
- Misc warnings by @seanm in https://github.com/fmtlib/fmt/pull/2801
- Fix incompatible between Jinja2 >= 3.1 and sphinx 3.3.0 by @phprus in https://github.com/fmtlib/fmt/pull/2836
- Remove dead code in ostream.h format_value by @jcelerier in https://github.com/fmtlib/fmt/pull/2843
- MSVC CMake generation optimization (13.6s -> 5.7s) by @mattiasljungstrom in https://github.com/fmtlib/fmt/pull/2852
- Suppress a -Wliteral-range warning on Apple M1 by @phprus in https://github.com/fmtlib/fmt/pull/2861
- Fixed all clang -Wsigned-enum-bitfield warnings by @seanm in https://github.com/fmtlib/fmt/pull/2882
- VS2022 17.2: C4189: 'zero': local variable is initialized but not referenced #2891 by @chronoxor in https://github.com/fmtlib/fmt/pull/2892
- Fix Windows max mix-up in chrono by @frithrah in https://github.com/fmtlib/fmt/pull/2903
- Skip cmake targets inclusion if fmt::fmt already exists by @kieselnb in https://github.com/fmtlib/fmt/pull/2907
- Add xchar support for write_escaped_string. by @phprus in https://github.com/fmtlib/fmt/pull/2904
- Visual Studio 2022: fmt/format.h(1526,27): warning C4127: conditional expression is constant #2908 by @chronoxor in https://github.com/fmtlib/fmt/pull/2909
- Improve std formatters by @phprus in https://github.com/fmtlib/fmt/pull/2902
- chore: Set permissions for GitHub actions by @nathannaveen in https://github.com/fmtlib/fmt/pull/2913
- Add support for std.h in Bazel build by @Vertexwahn in https://github.com/fmtlib/fmt/pull/2914
- use qualified format_to call to avoid ADL conflict with std::format_to by @Agga in https://github.com/fmtlib/fmt/pull/2922
- Docs: add comment about empty format context range by @leha-bot in https://github.com/fmtlib/fmt/pull/2924
- Make std::filesystem::path formatter utf-8 compatible. by @phprus in https://github.com/fmtlib/fmt/pull/2918
- Fix 'duplicate symbol' error. by @phprus in https://github.com/fmtlib/fmt/pull/2927
- Added a FMT_STRING wrapper for system_error() call. by @madmaxoft in https://github.com/fmtlib/fmt/pull/2929
- Make the tests pass on a CHERI system. by @davidchisnall in https://github.com/fmtlib/fmt/pull/2932
- fix -Wsign-conversion warnings by @JurajX in https://github.com/fmtlib/fmt/pull/2937
- Remove
/source-charset:utf-8
compile option. by @phprus in https://github.com/fmtlib/fmt/pull/2938 - Fix is_formattable for tuple-like types. by @jehelset in https://github.com/fmtlib/fmt/pull/2940
- Fix enable_ifs for map formatter: map formatter requires std::pair formatter but never uses it by @BrukerJWD in https://github.com/fmtlib/fmt/pull/2944
- Add support for 'std::variant' in C++17 by @jehelset in https://github.com/fmtlib/fmt/pull/2941
- Fix std::variant, std::filesystem::path tests on GCC-8, Clang-7,8. by @phprus in https://github.com/fmtlib/fmt/pull/2951
- Fix partial specialization problem for filesystem for Visual Studio by @Dani-Hub in https://github.com/fmtlib/fmt/pull/2957
- Add support Microsoft Visual Studio 2022. by @phprus in https://github.com/fmtlib/fmt/pull/2960
New Contributors
- @Pokechu22 made their first contribution in https://github.com/fmtlib/fmt/pull/2712
- @Tobi823 made their first contribution in https://github.com/fmtlib/fmt/pull/2724
- @ivan-volnov made their first contribution in https://github.com/fmtlib/fmt/pull/2725
- @VasiliPupkin256 made their first contribution in https://github.com/fmtlib/fmt/pull/2728
- @arogge made their first contribution in https://github.com/fmtlib/fmt/pull/2733
- @barcharcraz made their first contribution in https://github.com/fmtlib/fmt/pull/2742
- @kambala-decapitator made their first contribution in https://github.com/fmtlib/fmt/pull/2772
- @setoye made their first contribution in https://github.com/fmtlib/fmt/pull/2789
- @dalboris made their first contribution in https://github.com/fmtlib/fmt/pull/2797
- @rbrugo made their first contribution in https://github.com/fmtlib/fmt/pull/2793
- @rtobar made their first contribution in https://github.com/fmtlib/fmt/pull/2803
- @anoonD made their first contribution in https://github.com/fmtlib/fmt/pull/2815
- @timsong-cpp made their first contribution in https://github.com/fmtlib/fmt/pull/2819
- @seanm made their first contribution in https://github.com/fmtlib/fmt/pull/2801
- @frithrah made their first contribution in https://github.com/fmtlib/fmt/pull/2903
- @kieselnb made their first contribution in https://github.com/fmtlib/fmt/pull/2907
- @nathannaveen made their first contribution in https://github.com/fmtlib/fmt/pull/2913
- @Agga made their first contribution in https://github.com/fmtlib/fmt/pull/2922
- @leha-bot made their first contribution in https://github.com/fmtlib/fmt/pull/2924
- @madmaxoft made their first contribution in https://github.com/fmtlib/fmt/pull/2929
- @davidchisnall made their first contribution in https://github.com/fmtlib/fmt/pull/2932
- @JurajX made their first contribution in https://github.com/fmtlib/fmt/pull/2937
- @jehelset made their first contribution in https://github.com/fmtlib/fmt/pull/2940
- @Dani-Hub made their first contribution in https://github.com/fmtlib/fmt/pull/2957
Full Changelog: https://github.com/fmtlib/fmt/compare/8.1.1...9.0.0
1、 fmt-9.0.0.zip 1.2MB