C++ Format v5.3.0 Release Notes

Release Date: 2018-12-28 // over 5 years ago
    • πŸ‘ Introduced experimental chrono formatting support:

    .. code:: c++

     #include <fmt/chrono.h>
    
     int main() {
       using namespace std::literals::chrono_literals;
       fmt::print("Default format: {} {}\n", 42s, 100ms);
       fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);
     }
    

    prints::

     Default format: 42s 100ms
     strftime-like format: 03:15:30
    
    • βž• Added experimental support for emphasis (bold, italic, underline, strikethrough), colored output to a file stream, and improved colored formatting API (#961 <https://github.com/fmtlib/fmt/pull/961>, #967 <https://github.com/fmtlib/fmt/pull/967>, #973 <https://github.com/fmtlib/fmt/pull/973>_):

    .. code:: c++

     #include <fmt/color.h>
    
     int main() {
       print(fg(fmt::color::crimson) | fmt::emphasis::bold,
             "Hello, {}!\n", "world");
       print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
             fmt::emphasis::underline, "Hello, {}!\n", "ΠΌΠΈΡ€");
       print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
             "Hello, {}!\n", "δΈ–η•Œ");
     }
    

    prints the following on modern terminals with RGB color support:

    .. image:: https://user-images.githubusercontent.com/576385/ 50405788-b66e7500-076e-11e9-9592-7324d1f951d8.png

    Thanks @Rakete1111 (Nicolas) <https://github.com/Rakete1111>_.

    • βž• Added support for 4-bit terminal colors (#968 <https://github.com/fmtlib/fmt/issues/968>, #974 <https://github.com/fmtlib/fmt/pull/974>)

    .. code:: c++

     #include <fmt/color.h>
    
     int main() {
       print(fg(fmt::terminal_color::red), "stop\n");
     }
    

    Note that these colors vary by terminal:

    .. image:: https://user-images.githubusercontent.com/576385/ 50405925-dbfc7e00-0770-11e9-9b85-333fab0af9ac.png

    Thanks @Rakete1111 (Nicolas) <https://github.com/Rakete1111>_.

    • Parameterized formatting functions on the type of the format string (#880 <https://github.com/fmtlib/fmt/issues/880>, #881 <https://github.com/fmtlib/fmt/pull/881>, #883 <https://github.com/fmtlib/fmt/pull/883>, #885 <https://github.com/fmtlib/fmt/pull/885>, #897 <https://github.com/fmtlib/fmt/pull/897>, #920 <https://github.com/fmtlib/fmt/issues/920>). Any object of type S that has an overloaded to_string_view(const S&) returning fmt::string_view can be used as a format string:

    .. code:: c++

     namespace my_ns {
     inline string_view to_string_view(const my_string& s) {
       return {s.data(), s.length()};
     }
     }
    
     std::string message = fmt::format(my_string("The answer is {}."), 42);
    

    Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>_.

    • Made std::string_view work as a format string (#898 <https://github.com/fmtlib/fmt/pull/898>_):

    .. code:: c++

     auto message = fmt::format(std::string_view("The answer is {}."), 42);
    

    Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>_.

    • βž• Added wide string support to compile-time format string checks (#924 <https://github.com/fmtlib/fmt/pull/924>_):

    .. code:: c++

     print(fmt(L"{:f}"), 42); // compile-time error: invalid type specifier
    

    Thanks @XZiar <https://github.com/XZiar>_.

    • πŸ–¨ Made colored print functions work with wide strings (#867 <https://github.com/fmtlib/fmt/pull/867>_):

    .. code:: c++

     #include <fmt/color.h>
    
     int main() {
       print(fg(fmt::color::red), L"{}\n", 42);
     }
    

    Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>_.

    • πŸ‘ Introduced experimental Unicode support (#628 <https://github.com/fmtlib/fmt/issues/628>, #891 <https://github.com/fmtlib/fmt/pull/891>):

    .. code:: c++

     using namespace fmt::literals;
     auto s = fmt::format("{:*^5}"_u, "🀑"_u); // s == "**🀑**"_u
    
    • πŸ‘Œ Improved locale support:

    .. code:: c++

     #include <fmt/locale.h>
    
     struct numpunct : std::numpunct<char> {
      protected:
       char do_thousands_sep() const override { return '~'; }
     };
    
     std::locale loc;
     auto s = fmt::format(std::locale(loc, new numpunct()), "{:n}", 1234567);
     // s == "1~234~567"
    
    • Constrained formatting functions on proper iterator types (#921 <https://github.com/fmtlib/fmt/pull/921>). Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>.

    • πŸ–¨ Added make_printf_args and make_wprintf_args functions (#934 <https://github.com/fmtlib/fmt/pull/934>). Thanks @tnovotny <https://github.com/tnovotny>.

    • πŸ“œ Deprecated fmt::visit, parse_context, and wparse_context. Use fmt::visit_format_arg, format_parse_context, and wformat_parse_context instead.

    • πŸ›  Removed undocumented basic_fixed_buffer which has been superseded by the iterator-based API (#873 <https://github.com/fmtlib/fmt/issues/873>, #902 <https://github.com/fmtlib/fmt/pull/902>). Thanks @superfunc (hollywood programmer) <https://github.com/superfunc>_.

    • Disallowed repeated leading zeros in an argument ID:

    .. code:: c++

     fmt::print("{000}", 42); // error
    
    • πŸ‘ Reintroduced support for gcc 4.4.

    • πŸ›  Fixed compilation on platforms with exotic double (#878 <https://github.com/fmtlib/fmt/issues/878>_).

    • πŸ‘Œ Improved documentation (#164 <https://github.com/fmtlib/fmt/issues/164>, #877 <https://github.com/fmtlib/fmt/issues/877>, #901 <https://github.com/fmtlib/fmt/pull/901>, #906 <https://github.com/fmtlib/fmt/pull/906>, #979 <https://github.com/fmtlib/fmt/pull/979>). Thanks @kookjr (Mathew Cucuzella) <https://github.com/kookjr>, @DarkDimius (Dmitry Petrashko) <https://github.com/DarkDimius>, @HecticSerenity <https://github.com/HecticSerenity>.

    • βž• Added pkgconfig support which makes it easier to consume the library from meson and other build systems (#916 <https://github.com/fmtlib/fmt/pull/916>). Thanks @colemickens (Cole Mickens) <https://github.com/colemickens>.

    • πŸ— Various build improvements (#909 <https://github.com/fmtlib/fmt/pull/909>, #926 <https://github.com/fmtlib/fmt/pull/926>, #937 <https://github.com/fmtlib/fmt/pull/937>, #953 <https://github.com/fmtlib/fmt/pull/953>, #959 <https://github.com/fmtlib/fmt/pull/959>). Thanks @tchaikov (Kefu Chai) <https://github.com/tchaikov>, @luncliff (Park DongHa) <https://github.com/luncliff>, @AndreasSchoenle (Andreas SchΓΆnle) <https://github.com/AndreasSchoenle>, @hotwatermorning <https://github.com/hotwatermorning>, @Zefz (JohanJansen) <https://github.com/Zefz>.

    • πŸ‘Œ Improved string_view construction performance (#914 <https://github.com/fmtlib/fmt/pull/914>). Thanks @gabime (Gabi Melman) <https://github.com/gabime>.

    • πŸ›  Fixed non-matching char types (#895 <https://github.com/fmtlib/fmt/pull/895>). Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>.

    • Fixed format_to_n with std::back_insert_iterator (#913 <https://github.com/fmtlib/fmt/pull/913>). Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>.

    • πŸ›  Fixed locale-dependent formatting (#905 <https://github.com/fmtlib/fmt/issues/905>_).

    • πŸ›  Fixed various compiler warnings and errors (#882 <https://github.com/fmtlib/fmt/pull/882>, #886 <https://github.com/fmtlib/fmt/pull/886>, #933 <https://github.com/fmtlib/fmt/pull/933>, #941 <https://github.com/fmtlib/fmt/pull/941>, #931 <https://github.com/fmtlib/fmt/issues/931>, #943 <https://github.com/fmtlib/fmt/pull/943>, #954 <https://github.com/fmtlib/fmt/pull/954>, #956 <https://github.com/fmtlib/fmt/pull/956>, #962 <https://github.com/fmtlib/fmt/pull/962>, #965 <https://github.com/fmtlib/fmt/issues/965>, #977 <https://github.com/fmtlib/fmt/issues/977>, #983 <https://github.com/fmtlib/fmt/pull/983>, #989 <https://github.com/fmtlib/fmt/pull/989>). Thanks @Luthaf (Guillaume Fraux) <https://github.com/Luthaf>, @stevenhoving (Steven Hoving) <https://github.com/stevenhoving>, @christinaa (Kristina Brooks) <https://github.com/christinaa>, @lgritz (Larry Gritz) <https://github.com/lgritz>, @DanielaE (Daniela Engert) <https://github.com/DanielaE>, @0x8000-0000 (Sign Bit) <https://github.com/0x8000-0000>, @liuping1997 <https://github.com/liuping1997>.