MyGit

9.0.0

fmtlib/fmt

版本发布时间: 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

New Contributors

Full Changelog: https://github.com/fmtlib/fmt/compare/8.1.1...9.0.0

相关地址:原始地址 下载(tar) 下载(zip)

1、 fmt-9.0.0.zip 1.2MB

查看:2022-07-05发行的版本