From c1441ae4c4ec35ceb3909f7f6095e459a6fbf5c3 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 12 May 2018 16:02:20 -0700 Subject: [PATCH 1/7] Update ChangeLog.rst --- ChangeLog.rst | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/ChangeLog.rst b/ChangeLog.rst index 03cb8213..d0742917 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -30,20 +30,36 @@ * Added a section on `formatting user-defined `_ types to the docs (`#393 `_). Thanks `@pwm1234 (Phil) `_. -* Fixed compilation on Android (`#381 `_). - Thanks `@hghwng (Hugh Wang) `_. - -* Fixed Linux compilation with ``-fno-exceptions`` (`#402 `_). - Thanks `@JanHellwig (Jan Hellwig) `_. - * Implemented thread-safe time formatting (`#395 `_, `#396 `_). Thanks `@codicodi `_. +* Added a version macro ``FMT_VERSION`` (`#411 `_) + * Removed unnecessary ``fmt/`` prefix in includes (`#397 `_). Thanks `@chronoxor (Ivan Shynkarenka) `_. * Renamed ``CHAR_WIDTH`` to ``CHAR_SIZE`` to avoid collision with ISO/IEC TS 18661-1:2014 macro. +* Replaced literal 0 with ``nullptr`` in pointer contexts (`#409 `_). + Thanks `@alabuzhev (Alex Alabuzhev) `_. + +* Fixed minimal supported library subset (`#418 `_, `#419 `_, `#420 `_). + Thanks `@alabuzhev (Alex Alabuzhev) `_. + +* Fixed compilation on Android (`#381 `_). + Thanks `@hghwng (Hugh Wang) `_. + +* Fixed compilation with ``-fno-exceptions`` (`#402 `_, `#405 `_). + Thanks `@JanHellwig (Jan Hellwig) `_. + +* Fixed compilation as a shared library with Clang (`#413 `_). Thanks `@foonathan (Jonathan Müller) `_. + +* Fixed test compilation on FreeBSD. (`#433 `_). Thanks `@WscriChy `_. + +* Fixed signbit detection (`#423 `_). + +* Fixed various warnings (`#409 `_). Thanks `@Lectem `_, `@chenhayat (Chen Hayat) `_. + 4.1.0 - 2017-12-20 ------------------ From d3f6c841c1c8bf20df32f6f560a0bf4a573b7f51 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 13 May 2018 07:22:41 -0700 Subject: [PATCH 2/7] Update ChangeLog.rst --- ChangeLog.rst | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/ChangeLog.rst b/ChangeLog.rst index d0742917..f2c28956 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -3,7 +3,7 @@ * Added a requirement for compiler support for variadic templates and dropped ``FMT_VARIADIC_*`` emulation macros. Variadic templates are available since GCC 4.4, Clang 2.9 and MSVC 18.0 (2013). For older compilers use `version 4.x `_ which continues to be maintained. -* Renamed symbols to follow standard C++ naming conventions and cleaned the argument handling API: ``ArgList`` -> ``format_args``, ``ArgArray`` -> ``format_arg_store``, etc. +* Renamed symbols to follow standard C++ naming conventions and proposed a subset of the library for standardization in `P0645R2 Text Formatting `_. * Added the `make_format_args `_ function for capturing formatting arguments: @@ -30,10 +30,21 @@ * Added a section on `formatting user-defined `_ types to the docs (`#393 `_). Thanks `@pwm1234 (Phil) `_. +* Added an experimental ``join`` function that allows formating a range of values (`godbolt `_, `#466 `_): + + .. code:: c++ + + std::vector v = {1, 2, 3}; + print("{}", fmt::join(v.begin(), v.end(), ", ")); // prints "1, 2, 3" + + Thanks `@olivier80 `_. + +* Removed the Write API in favor of the `Format API `_ with compile-time handling of format strings. + * Implemented thread-safe time formatting (`#395 `_, `#396 `_). Thanks `@codicodi `_. -* Added a version macro ``FMT_VERSION`` (`#411 `_) +* Added a version macro ``FMT_VERSION`` (`#411 `_). * Removed unnecessary ``fmt/`` prefix in includes (`#397 `_). Thanks `@chronoxor (Ivan Shynkarenka) `_. @@ -42,6 +53,19 @@ * Replaced literal 0 with ``nullptr`` in pointer contexts (`#409 `_). Thanks `@alabuzhev (Alex Alabuzhev) `_. + +* Added ``std::basic_string`` allocator support to ``fmt::string_view`` (`#441 `_). + Thanks `@glebov-andrey (Andrey Glebov) `_. + +* Stopped exporting the ``-std=c++11`` flag from the ``fmt`` target (`#445 `_). + Thanks `@EricWF (Eric) `_. + +* Made ``%s`` a generic format specifier that works with any argument type in ``fmt::printf`` (`#453 `_). + Thanks `@mojoBrendan `_: + + .. code:: c++ + + fmt::printf("%s", 42); * Fixed minimal supported library subset (`#418 `_, `#419 `_, `#420 `_). Thanks `@alabuzhev (Alex Alabuzhev) `_. @@ -54,10 +78,20 @@ * Fixed compilation as a shared library with Clang (`#413 `_). Thanks `@foonathan (Jonathan Müller) `_. -* Fixed test compilation on FreeBSD. (`#433 `_). Thanks `@WscriChy `_. +* Fixed test compilation on FreeBSD (`#433 `_). Thanks `@WscriChy `_. + +* Fixed a name conflict with Xlib (`#483 `_). * Fixed signbit detection (`#423 `_). +* Fixed missing intrinsic when included from C++/CLI (`#457 `_). Thanks `@calumr (Calum Robinson) `_. + +* Fixed Android not being detected with NDK 13b toolchain (`#458 `_). Thanks `@Gachapen (Magnus Bjerke Vik) `_. + +* Added ``SOURCELINK_SUFFIX`` for compatibility with Sphinx 1.5 (`#497 `_). Thanks `@ginggs (Graham Inggs) `_. + +* Added ``FMT_API`` declarations where needed for building a DLL (`#469 `_). Thanks `@richardeakin (Richard Eakin) `_. + * Fixed various warnings (`#409 `_). Thanks `@Lectem `_, `@chenhayat (Chen Hayat) `_. 4.1.0 - 2017-12-20 From 3aa29115795ea2d79df72fff4dbef2bd12469d0a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 13 May 2018 08:02:06 -0700 Subject: [PATCH 3/7] Update ChangeLog.rst --- ChangeLog.rst | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/ChangeLog.rst b/ChangeLog.rst index f2c28956..3db28ca8 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -28,16 +28,9 @@ template std::string format(string_view format_str, const Args & ... args); -* Added a section on `formatting user-defined `_ types to the docs (`#393 `_). Thanks `@pwm1234 (Phil) `_. +* Added a section on `formatting user-defined types `_ to the docs (`#393 `_). Thanks `@pwm1234 (Phil) `_. -* Added an experimental ``join`` function that allows formating a range of values (`godbolt `_, `#466 `_): - - .. code:: c++ - - std::vector v = {1, 2, 3}; - print("{}", fmt::join(v.begin(), v.end(), ", ")); // prints "1, 2, 3" - - Thanks `@olivier80 `_. +* Added a section describing `the use of header-only target with CMake `_ to the docs (`#515 `_). Thanks `@ibell (Ian Bell) `_. * Removed the Write API in favor of the `Format API `_ with compile-time handling of format strings. @@ -67,6 +60,9 @@ fmt::printf("%s", 42); +* Placed CMake imported targets in the `fmt` namespace (`#511 `_, `#513 `_). + Thanks `@bjoernthiel (Bjoern Thiel) `_, `@niosHD (Mario Werner) `_. + * Fixed minimal supported library subset (`#418 `_, `#419 `_, `#420 `_). Thanks `@alabuzhev (Alex Alabuzhev) `_. From dfb65469325af8770f186e565d18c490097ee568 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 13 May 2018 08:04:39 -0700 Subject: [PATCH 4/7] Fix docs --- doc/api.rst | 4 ++-- doc/index.rst | 2 +- doc/usage.rst | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 9372743f..989adb92 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -49,8 +49,6 @@ arguments in the resulting string. .. doxygenfunction:: print(std::FILE *, string_view, const Args&...) .. doxygenfunction:: vprint(std::FILE *, string_view, format_args) -.. _format-api: - Named arguments --------------- @@ -81,6 +79,8 @@ Compatibility .. doxygentypedef:: fmt::string_view .. doxygentypedef:: fmt::wstring_view +.. _format-api: + Format API ========== diff --git a/doc/index.rst b/doc/index.rst index b7b2fa86..fa5701a4 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -16,7 +16,7 @@ alternative to C++ IOStreams. -.. _format-api: +.. _format-api-intro: Format API ---------- diff --git a/doc/usage.rst b/doc/usage.rst index ed0c3e2d..4d39882c 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -67,6 +67,7 @@ your ``CMakeLists.txt`` file:: add_subdirectory(fmt) or + :: add_subdirectory(fmt EXCLUDE_FROM_ALL) From 989378930af0c5250775ea34a338f02c48fd767c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 13 May 2018 08:53:04 -0700 Subject: [PATCH 5/7] Detect inline namespaces on gcc --- include/fmt/core.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 8580cc93..66597eed 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -134,7 +134,8 @@ #endif #ifndef FMT_BEGIN_NAMESPACE -# if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_MSC_VER >= 1900 +# if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_GCC_VERSION >= 404 || \ + FMT_MSC_VER >= 1900 # define FMT_INLINE_NAMESPACE inline namespace # define FMT_END_NAMESPACE }} # else From 3c0f8c2601f669a7e6aa90d0d82fc71ca1406a3e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 13 May 2018 08:53:16 -0700 Subject: [PATCH 6/7] Update ChangeLog --- ChangeLog.rst | 152 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 123 insertions(+), 29 deletions(-) diff --git a/ChangeLog.rst b/ChangeLog.rst index 3db28ca8..5fa7b9c5 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,11 +1,58 @@ 5.0.0 - TBD ----------- -* Added a requirement for compiler support for variadic templates and dropped ``FMT_VARIADIC_*`` emulation macros. Variadic templates are available since GCC 4.4, Clang 2.9 and MSVC 18.0 (2013). For older compilers use `version 4.x `_ which continues to be maintained. +* Added a requirement for compiler support for variadic templates and dropped + ``FMT_VARIADIC_*`` emulation macros. Variadic templates are available since + GCC 4.4, Clang 2.9 and MSVC 18.0 (2013). For older compilers use `version 4.x + `_ which continues to be + maintained. -* Renamed symbols to follow standard C++ naming conventions and proposed a subset of the library for standardization in `P0645R2 Text Formatting `_. +* Renamed symbols to follow standard C++ naming conventions and proposed a subset + of the library for standardization in `P0645R2 Text Formatting + `_. -* Added the `make_format_args `_ function for capturing formatting arguments: +* Swparated format string parsing and formatting in the extension API to enable + compile-time format-string processing. For example + + .. code:: c++ + + struct S {}; + + namespace fmt { + template <> + struct formatter { + constexpr auto parse(parse_context& ctx) { + auto it = ctx.begin(); + spec = *it; + if (spec != 'd' && spec != 's') + throw format_error("invalid specifier"); + ++it; + return it; + } + + template + auto format(S, FormatContext& ctx) { + return spec == 's' ? + format_to(ctx.begin(), "{}", "fourty-two") : + format_to(ctx.begin(), "{}", 42); + } + + char spec = 0; + }; + } + + std::string s = fmt::format(fmt("{:x}"), S()); + + will give a compile-time error due to invalid format specifier (`godbolt + `_):: + + ... + :12:45: error: expression '' is not a constant expression + throw format_error("invalid specifier"); + +* Added the `make_format_args + `_ + function for capturing formatting arguments: .. code:: c++ @@ -19,7 +66,8 @@ vreport_error(format, fmt::make_format_args(args...)); } -* Added prefix ``v`` to non-variadic functions taking ``format_args`` to distinguish them from variadic ones: +* Added prefix ``v`` to non-variadic functions taking ``format_args`` to + distinguish them from variadic ones: .. code:: c++ @@ -28,67 +76,110 @@ template std::string format(string_view format_str, const Args & ... args); -* Added a section on `formatting user-defined types `_ to the docs (`#393 `_). Thanks `@pwm1234 (Phil) `_. +* Switched from a custom null-terminated string view class to ``string_view`` + in the format API and provided ``fmt::string_view`` which implements a subset + of ``std::string_view`` API for pre-C++17 systems. -* Added a section describing `the use of header-only target with CMake `_ to the docs (`#515 `_). Thanks `@ibell (Ian Bell) `_. +* Removed the write API in favor of the `format API + `_ with compile-time handling of + format strings. -* Removed the Write API in favor of the `Format API `_ with compile-time handling of format strings. +* Added a section on `formatting user-defined types + `_ to the docs + (`#393 `_). + Thanks `@pwm1234 (Phil) `_. -* Implemented thread-safe time formatting (`#395 `_, `#396 `_). +* Added a section describing `the use of header-only target with CMake + `_ to the docs + (`#515 `_). + Thanks `@ibell (Ian Bell) `_. + +* Implemented thread-safe time formatting ( + `#395 `_, + `#396 `_). Thanks `@codicodi `_. -* Added a version macro ``FMT_VERSION`` (`#411 `_). +* Implemented more efficient handling of large number of format arguments. -* Removed unnecessary ``fmt/`` prefix in includes (`#397 `_). +* Added a version macro ``FMT_VERSION`` + (`#411 `_). + +* Removed unnecessary ``fmt/`` prefix in includes + (`#397 `_). Thanks `@chronoxor (Ivan Shynkarenka) `_. -* Renamed ``CHAR_WIDTH`` to ``CHAR_SIZE`` to avoid collision with ISO/IEC TS 18661-1:2014 macro. +* Renamed ``CHAR_WIDTH`` to ``CHAR_SIZE`` to avoid collision with ISO/IEC TS + 18661-1:2014 macro. -* Replaced literal 0 with ``nullptr`` in pointer contexts (`#409 `_). +* Replaced literal 0 with ``nullptr`` in pointer contexts + (`#409 `_). Thanks `@alabuzhev (Alex Alabuzhev) `_. -* Added ``std::basic_string`` allocator support to ``fmt::string_view`` (`#441 `_). +* Added ``std::basic_string`` allocator support to ``fmt::string_view`` + (`#441 `_). Thanks `@glebov-andrey (Andrey Glebov) `_. -* Stopped exporting the ``-std=c++11`` flag from the ``fmt`` target (`#445 `_). +* Stopped exporting the ``-std=c++11`` flag from the ``fmt`` target + (`#445 `_). Thanks `@EricWF (Eric) `_. -* Made ``%s`` a generic format specifier that works with any argument type in ``fmt::printf`` (`#453 `_). +* Made ``%s`` a generic format specifier that works with any argument type in + ``fmt::printf`` (`#453 `_). Thanks `@mojoBrendan `_: .. code:: c++ fmt::printf("%s", 42); -* Placed CMake imported targets in the `fmt` namespace (`#511 `_, `#513 `_). - Thanks `@bjoernthiel (Bjoern Thiel) `_, `@niosHD (Mario Werner) `_. +* Placed CMake imported targets in the `fmt` namespace ( + `#511 `_, + `#513 `_). + Thanks `@bjoernthiel (Bjoern Thiel) `_ and + `@niosHD (Mario Werner) `_. -* Fixed minimal supported library subset (`#418 `_, `#419 `_, `#420 `_). +* Fixed minimal supported library subset ( + `#418 `_, + `#419 `_, + `#420 `_). Thanks `@alabuzhev (Alex Alabuzhev) `_. -* Fixed compilation on Android (`#381 `_). +* Fixed compilation on Android + (`#381 `_). Thanks `@hghwng (Hugh Wang) `_. -* Fixed compilation with ``-fno-exceptions`` (`#402 `_, `#405 `_). +* Fixed compilation with ``-fno-exceptions`` ( + `#402 `_, + `#405 `_). Thanks `@JanHellwig (Jan Hellwig) `_. -* Fixed compilation as a shared library with Clang (`#413 `_). Thanks `@foonathan (Jonathan Müller) `_. +* Fixed compilation as a shared library with Clang + (`#413 `_). + Thanks `@foonathan (Jonathan Müller) `_. -* Fixed test compilation on FreeBSD (`#433 `_). Thanks `@WscriChy `_. +* Fixed test compilation on FreeBSD + (`#433 `_). + Thanks `@WscriChy `_. -* Fixed a name conflict with Xlib (`#483 `_). +* Fixed a name conflict with Xlib + (`#483 `_). * Fixed signbit detection (`#423 `_). -* Fixed missing intrinsic when included from C++/CLI (`#457 `_). Thanks `@calumr (Calum Robinson) `_. +* Fixed missing intrinsic when included from C++/CLI + (`#457 `_). + Thanks `@calumr (Calum Robinson) `_. -* Fixed Android not being detected with NDK 13b toolchain (`#458 `_). Thanks `@Gachapen (Magnus Bjerke Vik) `_. +* Fixed Android not being detected with NDK 13b toolchain + (`#458 `_). + Thanks `@Gachapen (Magnus Bjerke Vik) `_. -* Added ``SOURCELINK_SUFFIX`` for compatibility with Sphinx 1.5 (`#497 `_). Thanks `@ginggs (Graham Inggs) `_. +* Added ``SOURCELINK_SUFFIX`` for compatibility with Sphinx 1.5 + (`#497 `_). + Thanks `@ginggs (Graham Inggs) `_. -* Added ``FMT_API`` declarations where needed for building a DLL (`#469 `_). Thanks `@richardeakin (Richard Eakin) `_. - -* Fixed various warnings (`#409 `_). Thanks `@Lectem `_, `@chenhayat (Chen Hayat) `_. +* Added ``FMT_API`` declarations where needed for building a DLL + (`#469 `_). + Thanks `@richardeakin (Richard Eakin) `_. 4.1.0 - 2017-12-20 ------------------ @@ -339,6 +430,9 @@ `@chenhayat (Chen Hayat) `_ and `@trozen `_. +* Worked around a broken ``__builtin_clz`` in clang with MS codegen + (`#519 `_). + * Removed redundant include (`#479 `_). From ad23270ec71dbcd90bde5e2479f37844b1a8f7da Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 13 May 2018 09:11:29 -0700 Subject: [PATCH 7/7] Document to_wstring --- doc/api.rst | 2 ++ include/fmt/format.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/doc/api.rst b/doc/api.rst index 989adb92..b65a8fc6 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -153,6 +153,8 @@ Utilities .. doxygenfunction:: fmt::to_string(const T&) +.. doxygenfunction:: fmt::to_wstring(const T&) + .. doxygenclass:: fmt::basic_memory_buffer :protected-members: :members: diff --git a/include/fmt/format.h b/include/fmt/format.h index a513c4ab..07c644aa 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3390,6 +3390,11 @@ std::string to_string(const T &value) { return str; } +/** + \rst + Converts *value* to ``std::wstring`` using the default format for type *T*. + \endrst + */ template std::wstring to_wstring(const T &value) { std::wstring str;