From 9ec3bea2d6e2c4e92798dad6dc4679d287202f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Fri, 23 Sep 2016 16:39:58 +0200 Subject: [PATCH 1/4] Add FMT_OVERRIDE macro to allow specifying overriding functions in c++11 compilers --- fmt/format.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fmt/format.h b/fmt/format.h index 0f471cc4..55361ecd 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -194,6 +194,17 @@ typedef __int64 intmax_t; # endif #endif +#ifndef FMT_OVERRIDE +# if FMT_USE_OVERRIDE || FMT_HAS_FEATURE(cxx_override) || \ + (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \ + FMT_MSC_VER >= 1900 +# define FMT_OVERRIDE override +# else +# define FMT_OVERRIDE +# endif +#endif + + // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class #ifndef FMT_USE_DELETED_FUNCTIONS @@ -678,7 +689,7 @@ class MemoryBuffer : private Allocator, public Buffer { } protected: - void grow(std::size_t size); + void grow(std::size_t size) FMT_OVERRIDE; public: explicit MemoryBuffer(const Allocator &alloc = Allocator()) From cee50b7572e4416f5aa7a2a6068543c1e5cd04a9 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 1 Oct 2016 21:32:16 -0700 Subject: [PATCH 2/4] Fix compilation on Cygwin (#388) --- fmt/posix.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fmt/posix.h b/fmt/posix.h index 7c2b0b5e..d4cd1198 100644 --- a/fmt/posix.h +++ b/fmt/posix.h @@ -10,7 +10,7 @@ #ifndef FMT_POSIX_H_ #define FMT_POSIX_H_ -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(__CYGWIN__) // Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/. # undef __STRICT_ANSI__ #endif @@ -302,7 +302,8 @@ class File { // Returns the memory page size. long getpagesize(); -#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && !defined(__ANDROID__) +#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \ + !defined(__ANDROID__) && !defined(__CYGWIN__) # define FMT_LOCALE #endif From 88c4bc33d22c2f292044e05f97dd772a4dd9134d Mon Sep 17 00:00:00 2001 From: Philip Miller Date: Wed, 5 Oct 2016 15:04:08 -0400 Subject: [PATCH 3/4] Document use of format_arg for user-defined type --- doc/api.rst | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/doc/api.rst b/doc/api.rst index ba847ae3..769284cf 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -58,6 +58,39 @@ formatting:: The format string syntax is described in the documentation of `strftime `_. +Formatting User-Defined types +----------------------------- + +A custom ``format_arg`` function may be implemented and used to format any user- +defined type. That is how date and time formatting described in the previous +section is implemented in :file:`fmt/time.h`. The following example shows how to implement custom formatting for a user-defined structure. + +:: + + struct MyStruct { double a, b, c, d; }; + + void format_arg(fmt::BasicFormatter &f, + const char *&format_str, const MyStruct &s) { + f.writer().write("[MyStruct: a={:.1f}, b={:.2f}, c={:.3f}, d={:.4f}]", + s.a, s.b, s.c, s.d); + } + + void f() + { + MyStruct m = { 1, 2, 3, 4 }; + std::string s = fmt::format("m={}", n); + // s == "m=[MyStruct: a=1.0, b=2.00, c=3.000, d=4.0000]" + } + +Note in the example above the ``format_arg`` function ignores the contents of +``format_str`` so the type will always be formatted as specified. See +``format_arg`` in :file:`fmt/time.h` for an advanced example of how to use +the ``format_str`` argument to customize the formatted output. + +This section shows how to define a custom format function for a user-defined +type. The next section describes how to get ``fmt`` to use a conventional stream +output ``operator<<`` when one is defined for a user-defined type. + ``std::ostream`` support ------------------------ From 4809e2956a9ec04e97f026c5df224349f61179b0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 6 Oct 2016 07:38:19 -0700 Subject: [PATCH 4/4] Minor documentation changes --- doc/api.rst | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 769284cf..5a93b4aa 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -58,29 +58,26 @@ formatting:: The format string syntax is described in the documentation of `strftime `_. -Formatting User-Defined types +Formatting user-defined types ----------------------------- -A custom ``format_arg`` function may be implemented and used to format any user- -defined type. That is how date and time formatting described in the previous -section is implemented in :file:`fmt/time.h`. The following example shows how to implement custom formatting for a user-defined structure. +A custom ``format_arg`` function may be implemented and used to format any +user-defined type. That is how date and time formatting described in the +previous section is implemented in :file:`fmt/time.h`. The following example +shows how to implement custom formatting for a user-defined structure. :: - struct MyStruct { double a, b, c, d; }; + struct MyStruct { double a, b; }; void format_arg(fmt::BasicFormatter &f, - const char *&format_str, const MyStruct &s) { - f.writer().write("[MyStruct: a={:.1f}, b={:.2f}, c={:.3f}, d={:.4f}]", - s.a, s.b, s.c, s.d); + const char *&format_str, const MyStruct &s) { + f.writer().write("[MyStruct: a={:.1f}, b={:.2f}]", s.a, s.b); } - void f() - { - MyStruct m = { 1, 2, 3, 4 }; - std::string s = fmt::format("m={}", n); - // s == "m=[MyStruct: a=1.0, b=2.00, c=3.000, d=4.0000]" - } + MyStruct m = { 1, 2 }; + std::string s = fmt::format("m={}", n); + // s == "m=[MyStruct: a=1.0, b=2.00]" Note in the example above the ``format_arg`` function ignores the contents of ``format_str`` so the type will always be formatted as specified. See