diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..ec9a5457 --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +BasedOnStyle: Google +Language: Cpp +Standard: Cpp11 + +ColumnLimit: 80 + +AlwaysBreakTemplateDeclarations: true +AllowShortIfStatementsOnASingleLine: false + +AlignAfterOpenBracket: AlwaysBreak +BinPackArguments: false +BinPackParameters: false diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 7d8559d4..c44866e0 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -18,7 +18,7 @@ FMT_BEGIN_NAMESPACE -namespace internal{ +namespace internal { enum class numeric_system { standard, @@ -28,152 +28,154 @@ enum class numeric_system { // Parses a put_time-like format string and invokes handler actions. template -FMT_CONSTEXPR const Char *parse_chrono_format( - const Char *begin, const Char *end, Handler &&handler) { +FMT_CONSTEXPR const Char *parse_chrono_format(const Char *begin, + const Char *end, + Handler &&handler) { auto ptr = begin; while (ptr != end) { auto c = *ptr; - if (c == '}') break; + if (c == '}') + break; if (c != '%') { ++ptr; continue; } if (begin != ptr) handler.on_text(begin, ptr); - ++ptr; // consume '%' + ++ptr; // consume '%' if (ptr == end) throw format_error("invalid format"); c = *ptr++; switch (c) { - case '%': - handler.on_text(ptr - 1, ptr); - break; - case 'n': { - const char newline[] = "\n"; - handler.on_text(newline, newline + 1); - break; - } - case 't': { - const char tab[] = "\t"; - handler.on_text(tab, tab + 1); - break; - } - // Day of the week: - case 'a': - handler.on_abbr_weekday(); - break; - case 'A': - handler.on_full_weekday(); - break; - case 'w': - handler.on_dec0_weekday(numeric_system::standard); - break; - case 'u': - handler.on_dec1_weekday(numeric_system::standard); - break; - // Month: - case 'b': - handler.on_abbr_month(); - break; - case 'B': - handler.on_full_month(); - break; - // Hour, minute, second: - case 'H': - handler.on_24_hour(numeric_system::standard); - break; - case 'I': - handler.on_12_hour(numeric_system::standard); - break; - case 'M': - handler.on_minute(numeric_system::standard); - break; - case 'S': - handler.on_second(numeric_system::standard); - break; - // Other: - case 'c': - handler.on_datetime(numeric_system::standard); - break; - case 'x': - handler.on_loc_date(numeric_system::standard); - break; - case 'X': - handler.on_loc_time(numeric_system::standard); - break; - case 'D': - handler.on_us_date(); - break; - case 'F': - handler.on_iso_date(); - break; - case 'r': - handler.on_12_hour_time(); - break; - case 'R': - handler.on_24_hour_time(); - break; - case 'T': - handler.on_iso_time(); - break; - case 'p': - handler.on_am_pm(); - break; - case 'z': - handler.on_utc_offset(); - break; - case 'Z': - handler.on_tz_name(); - break; - // Alternative representation: - case 'E': { - if (ptr == end) - throw format_error("invalid format"); - c = *ptr++; - switch (c) { - case 'c': - handler.on_datetime(numeric_system::alternative); + case '%': + handler.on_text(ptr - 1, ptr); break; - case 'x': - handler.on_loc_date(numeric_system::alternative); + case 'n': { + const char newline[] = "\n"; + handler.on_text(newline, newline + 1); break; - case 'X': - handler.on_loc_time(numeric_system::alternative); - break; - default: - throw format_error("invalid format"); } - break; - } - case 'O': - if (ptr == end) - throw format_error("invalid format"); - c = *ptr++; - switch (c) { + case 't': { + const char tab[] = "\t"; + handler.on_text(tab, tab + 1); + break; + } + // Day of the week: + case 'a': + handler.on_abbr_weekday(); + break; + case 'A': + handler.on_full_weekday(); + break; case 'w': - handler.on_dec0_weekday(numeric_system::alternative); + handler.on_dec0_weekday(numeric_system::standard); break; case 'u': - handler.on_dec1_weekday(numeric_system::alternative); + handler.on_dec1_weekday(numeric_system::standard); break; + // Month: + case 'b': + handler.on_abbr_month(); + break; + case 'B': + handler.on_full_month(); + break; + // Hour, minute, second: case 'H': - handler.on_24_hour(numeric_system::alternative); + handler.on_24_hour(numeric_system::standard); break; case 'I': - handler.on_12_hour(numeric_system::alternative); + handler.on_12_hour(numeric_system::standard); break; case 'M': - handler.on_minute(numeric_system::alternative); + handler.on_minute(numeric_system::standard); break; case 'S': - handler.on_second(numeric_system::alternative); + handler.on_second(numeric_system::standard); + break; + // Other: + case 'c': + handler.on_datetime(numeric_system::standard); + break; + case 'x': + handler.on_loc_date(numeric_system::standard); + break; + case 'X': + handler.on_loc_time(numeric_system::standard); + break; + case 'D': + handler.on_us_date(); + break; + case 'F': + handler.on_iso_date(); + break; + case 'r': + handler.on_12_hour_time(); + break; + case 'R': + handler.on_24_hour_time(); + break; + case 'T': + handler.on_iso_time(); + break; + case 'p': + handler.on_am_pm(); + break; + case 'z': + handler.on_utc_offset(); + break; + case 'Z': + handler.on_tz_name(); + break; + // Alternative representation: + case 'E': { + if (ptr == end) + throw format_error("invalid format"); + c = *ptr++; + switch (c) { + case 'c': + handler.on_datetime(numeric_system::alternative); + break; + case 'x': + handler.on_loc_date(numeric_system::alternative); + break; + case 'X': + handler.on_loc_time(numeric_system::alternative); + break; + default: + throw format_error("invalid format"); + } + break; + } + case 'O': + if (ptr == end) + throw format_error("invalid format"); + c = *ptr++; + switch (c) { + case 'w': + handler.on_dec0_weekday(numeric_system::alternative); + break; + case 'u': + handler.on_dec1_weekday(numeric_system::alternative); + break; + case 'H': + handler.on_24_hour(numeric_system::alternative); + break; + case 'I': + handler.on_12_hour(numeric_system::alternative); + break; + case 'M': + handler.on_minute(numeric_system::alternative); + break; + case 'S': + handler.on_second(numeric_system::alternative); + break; + default: + throw format_error("invalid format"); + } break; default: throw format_error("invalid format"); - } - break; - default: - throw format_error("invalid format"); } begin = ptr; } @@ -213,7 +215,8 @@ struct chrono_format_checker { template inline int to_int(Int value) { FMT_ASSERT(value >= (std::numeric_limits::min)() && - value <= (std::numeric_limits::max)(), "invalid value"); + value <= (std::numeric_limits::max)(), + "invalid value"); return static_cast(value); } @@ -227,7 +230,7 @@ struct chrono_formatter { typedef typename FormatContext::char_type char_type; explicit chrono_formatter(FormatContext &ctx) - : context(ctx), out(ctx.out()) {} + : context(ctx), out(ctx.out()) {} int hour() const { return to_int((s.count() / 3600) % 24); } @@ -341,30 +344,84 @@ struct chrono_formatter { }; } // namespace internal -template FMT_CONSTEXPR const char *get_units() { +template +FMT_CONSTEXPR const char *get_units() { return FMT_NULL; } -template <> FMT_CONSTEXPR const char *get_units() { return "as"; } -template <> FMT_CONSTEXPR const char *get_units() { return "fs"; } -template <> FMT_CONSTEXPR const char *get_units() { return "ps"; } -template <> FMT_CONSTEXPR const char *get_units() { return "ns"; } -template <> FMT_CONSTEXPR const char *get_units() { return "µs"; } -template <> FMT_CONSTEXPR const char *get_units() { return "ms"; } -template <> FMT_CONSTEXPR const char *get_units() { return "cs"; } -template <> FMT_CONSTEXPR const char *get_units() { return "ds"; } -template <> FMT_CONSTEXPR const char *get_units>() { return "s"; } -template <> FMT_CONSTEXPR const char *get_units() { return "das"; } -template <> FMT_CONSTEXPR const char *get_units() { return "hs"; } -template <> FMT_CONSTEXPR const char *get_units() { return "ks"; } -template <> FMT_CONSTEXPR const char *get_units() { return "Ms"; } -template <> FMT_CONSTEXPR const char *get_units() { return "Gs"; } -template <> FMT_CONSTEXPR const char *get_units() { return "Ts"; } -template <> FMT_CONSTEXPR const char *get_units() { return "Ps"; } -template <> FMT_CONSTEXPR const char *get_units() { return "Es"; } -template <> FMT_CONSTEXPR const char *get_units>() { +template <> +FMT_CONSTEXPR const char *get_units() { + return "as"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "fs"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "ps"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "ns"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "µs"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "ms"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "cs"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "ds"; +} +template <> +FMT_CONSTEXPR const char *get_units>() { + return "s"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "das"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "hs"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "ks"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "Ms"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "Gs"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "Ts"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "Ps"; +} +template <> +FMT_CONSTEXPR const char *get_units() { + return "Es"; +} +template <> +FMT_CONSTEXPR const char *get_units>() { return "m"; } -template <> FMT_CONSTEXPR const char *get_units>() { +template <> +FMT_CONSTEXPR const char *get_units>() { return "h"; } @@ -409,10 +466,12 @@ struct formatter, Char> { FMT_CONSTEXPR auto parse(basic_parse_context &ctx) -> decltype(ctx.begin()) { auto begin = ctx.begin(), end = ctx.end(); - if (begin == end) return begin; + if (begin == end) + return begin; spec_handler handler{*this, ctx}; begin = internal::parse_align(begin, end, handler); - if (begin == end) return begin; + if (begin == end) + return begin; begin = internal::parse_width(begin, end, handler); end = parse_chrono_format(begin, end, internal::chrono_format_checker()); format_str = basic_string_view(&*begin, end - begin); @@ -420,8 +479,7 @@ struct formatter, Char> { } template - auto format(const duration &d, FormatContext &ctx) - -> decltype(ctx.out()) { + auto format(const duration &d, FormatContext &ctx) -> decltype(ctx.out()) { auto begin = format_str.begin(), end = format_str.end(); if (begin == end || *begin == '}') { memory_buffer buf; @@ -433,8 +491,8 @@ struct formatter, Char> { format_to(buf, "{}[{}/{}]s", d.count(), Period::num, Period::den); typedef output_range range; basic_writer w(range(ctx.out())); - internal::handle_dynamic_spec( - spec.width_, width_ref, ctx); + internal::handle_dynamic_spec(spec.width_, + width_ref, ctx); w.write(buf.data(), buf.size(), spec); return w.out(); } diff --git a/include/fmt/color.h b/include/fmt/color.h index 8c96f7fd..5c0da531 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -20,12 +20,12 @@ FMT_API void vprint_colored(color c, string_view format, format_args args); FMT_API void vprint_colored(color c, wstring_view format, wformat_args args); template inline void print_colored(color c, string_view format_str, - const Args & ... args) { + const Args&... args) { vprint_colored(c, format_str, make_format_args(args...)); } template inline void print_colored(color c, wstring_view format_str, - const Args & ... args) { + const Args&... args) { vprint_colored(c, format_str, make_format_args(args...)); } @@ -47,6 +47,8 @@ inline void vprint_colored(color c, wstring_view format, wformat_args args) { #else +// clang-format off + enum class color : uint32_t { alice_blue = 0xF0F8FF, // rgb(240,248,255) antique_white = 0xFAEBD7, // rgb(250,235,215) @@ -191,6 +193,8 @@ enum class color : uint32_t { yellow_green = 0x9ACD32 // rgb(154,205,50) }; // enum class color +// clang-format on + enum class terminal_color : uint8_t { black = 30, red, @@ -223,12 +227,13 @@ enum class emphasis : uint8_t { struct rgb { FMT_CONSTEXPR_DECL rgb() : r(0), g(0), b(0) {} FMT_CONSTEXPR_DECL rgb(uint8_t r_, uint8_t g_, uint8_t b_) - : r(r_), g(g_), b(b_) {} + : r(r_), g(g_), b(b_) {} FMT_CONSTEXPR_DECL rgb(uint32_t hex) - : r((hex >> 16) & 0xFF), g((hex >> 8) & 0xFF), b((hex) & 0xFF) {} + : r((hex >> 16) & 0xFF), g((hex >> 8) & 0xFF), b((hex)&0xFF) {} FMT_CONSTEXPR_DECL rgb(color hex) - : r((uint32_t(hex) >> 16) & 0xFF), g((uint32_t(hex) >> 8) & 0xFF), - b(uint32_t(hex) & 0xFF) {} + : r((uint32_t(hex) >> 16) & 0xFF), + g((uint32_t(hex) >> 8) & 0xFF), + b(uint32_t(hex) & 0xFF) {} uint8_t r; uint8_t g; uint8_t b; @@ -238,18 +243,16 @@ namespace internal { // color is a struct of either a rgb color or a terminal color. struct color_type { - FMT_CONSTEXPR color_type() FMT_NOEXCEPT - : is_rgb(), value{} {} - FMT_CONSTEXPR color_type(color rgb_color) FMT_NOEXCEPT - : is_rgb(true), value{} { + FMT_CONSTEXPR color_type() FMT_NOEXCEPT : is_rgb(), value{} {} + FMT_CONSTEXPR color_type(color rgb_color) FMT_NOEXCEPT : is_rgb(true), + value{} { value.rgb_color = static_cast(rgb_color); } - FMT_CONSTEXPR color_type(rgb rgb_color) FMT_NOEXCEPT - : is_rgb(true), value{} { + FMT_CONSTEXPR color_type(rgb rgb_color) FMT_NOEXCEPT : is_rgb(true), value{} { value.rgb_color = (rgb_color.r << 16) + (rgb_color.g << 8) + rgb_color.b; } - FMT_CONSTEXPR color_type(terminal_color term_color) FMT_NOEXCEPT - : is_rgb(), value{} { + FMT_CONSTEXPR color_type(terminal_color term_color) FMT_NOEXCEPT : is_rgb(), + value{} { value.term_color = static_cast(term_color); } bool is_rgb; @@ -258,13 +261,15 @@ struct color_type { uint32_t rgb_color; } value; }; -} // namespace internal +} // namespace internal // Experimental text formatting support. class text_style { public: FMT_CONSTEXPR text_style(emphasis em = emphasis()) FMT_NOEXCEPT - : set_foreground_color(), set_background_color(), ems(em) {} + : set_foreground_color(), + set_background_color(), + ems(em) {} FMT_CONSTEXPR text_style &operator|=(const text_style &rhs) { if (!set_foreground_color) { @@ -290,8 +295,8 @@ class text_style { return *this; } - friend FMT_CONSTEXPR - text_style operator|(text_style lhs, const text_style &rhs) { + friend FMT_CONSTEXPR text_style operator|(text_style lhs, + const text_style &rhs) { return lhs |= rhs; } @@ -319,8 +324,8 @@ class text_style { return *this; } - friend FMT_CONSTEXPR - text_style operator&(text_style lhs, const text_style &rhs) { + friend FMT_CONSTEXPR text_style operator&(text_style lhs, + const text_style &rhs) { return lhs &= rhs; } @@ -346,20 +351,20 @@ class text_style { return ems; } -private: - FMT_CONSTEXPR text_style(bool is_foreground, - internal::color_type text_color) FMT_NOEXCEPT - : set_foreground_color(), - set_background_color(), - ems() { - if (is_foreground) { - foreground_color = text_color; - set_foreground_color = true; - } else { - background_color = text_color; - set_background_color = true; - } - } + private: + FMT_CONSTEXPR text_style(bool is_foreground, + internal::color_type text_color) FMT_NOEXCEPT + : set_foreground_color(), + set_background_color(), + ems() { + if (is_foreground) { + foreground_color = text_color; + set_foreground_color = true; + } else { + background_color = text_color; + set_background_color = true; + } + } friend FMT_CONSTEXPR_DECL text_style fg(internal::color_type foreground) FMT_NOEXCEPT; @@ -390,7 +395,7 @@ namespace internal { template struct ansi_color_escape { FMT_CONSTEXPR ansi_color_escape(internal::color_type text_color, - const char * esc) FMT_NOEXCEPT { + const char *esc) FMT_NOEXCEPT { // If we have a terminal color, we need to output another escape code // sequence. if (!text_color.is_rgb) { @@ -421,7 +426,7 @@ struct ansi_color_escape { buffer[i] = static_cast(esc[i]); } rgb color(text_color.value.rgb_color); - to_esc(color.r, buffer + 7, ';'); + to_esc(color.r, buffer + 7, ';'); to_esc(color.g, buffer + 11, ';'); to_esc(color.b, buffer + 15, 'm'); buffer[19] = static_cast(0); @@ -451,7 +456,7 @@ struct ansi_color_escape { } FMT_CONSTEXPR operator const Char *() const FMT_NOEXCEPT { return buffer; } -private: + private: Char buffer[7 + 3 * 4 + 1]; static FMT_CONSTEXPR void to_esc(uint8_t c, Char *out, @@ -464,20 +469,19 @@ private: }; template -FMT_CONSTEXPR ansi_color_escape -make_foreground_color(internal::color_type foreground) FMT_NOEXCEPT { +FMT_CONSTEXPR ansi_color_escape make_foreground_color( + internal::color_type foreground) FMT_NOEXCEPT { return ansi_color_escape(foreground, internal::data::FOREGROUND_COLOR); } template -FMT_CONSTEXPR ansi_color_escape -make_background_color(internal::color_type background) FMT_NOEXCEPT { +FMT_CONSTEXPR ansi_color_escape make_background_color( + internal::color_type background) FMT_NOEXCEPT { return ansi_color_escape(background, internal::data::BACKGROUND_COLOR); } template -FMT_CONSTEXPR ansi_color_escape -make_emphasis(emphasis em) FMT_NOEXCEPT { +FMT_CONSTEXPR ansi_color_escape make_emphasis(emphasis em) FMT_NOEXCEPT { return ansi_color_escape(em); } @@ -509,22 +513,20 @@ template <> struct is_string : std::false_type {}; template <> struct is_string : std::false_type {}; -} // namespace internal +} // namespace internal -template < - typename S, typename Char = typename internal::char_t::type> +template ::type> void vprint(std::FILE *f, const text_style &ts, const S &format, basic_format_args::type> args) { bool has_style = false; if (ts.has_emphasis()) { has_style = true; - internal::fputs( - internal::make_emphasis(ts.get_emphasis()), f); + internal::fputs(internal::make_emphasis(ts.get_emphasis()), f); } if (ts.has_foreground()) { has_style = true; internal::fputs( - internal::make_foreground_color(ts.get_foreground()), f); + internal::make_foreground_color(ts.get_foreground()), f); } if (ts.has_background()) { has_style = true; @@ -564,8 +566,7 @@ typename std::enable_if::value>::type print( */ template typename std::enable_if::value>::type print( - const text_style &ts, const String &format_str, - const Args &... args) { + const text_style &ts, const String &format_str, const Args &... args) { return print(stdout, ts, format_str, args...); } diff --git a/include/fmt/core.h b/include/fmt/core.h index 33830eef..ca5157ce 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -19,171 +19,178 @@ #define FMT_VERSION 50202 #ifdef __has_feature -# define FMT_HAS_FEATURE(x) __has_feature(x) +#define FMT_HAS_FEATURE(x) __has_feature(x) #else -# define FMT_HAS_FEATURE(x) 0 +#define FMT_HAS_FEATURE(x) 0 #endif #if defined(__has_include) && !defined(__INTELLISENSE__) && \ !(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1600) -# define FMT_HAS_INCLUDE(x) __has_include(x) +#define FMT_HAS_INCLUDE(x) __has_include(x) #else -# define FMT_HAS_INCLUDE(x) 0 +#define FMT_HAS_INCLUDE(x) 0 #endif #ifdef __has_cpp_attribute -# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) +#define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) #else -# define FMT_HAS_CPP_ATTRIBUTE(x) 0 +#define FMT_HAS_CPP_ATTRIBUTE(x) 0 #endif #if defined(__GNUC__) && !defined(__clang__) -# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +#define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) #else -# define FMT_GCC_VERSION 0 +#define FMT_GCC_VERSION 0 #endif #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -# define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION +#define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION #else -# define FMT_HAS_GXX_CXX11 0 +#define FMT_HAS_GXX_CXX11 0 #endif #ifdef _MSC_VER -# define FMT_MSC_VER _MSC_VER +#define FMT_MSC_VER _MSC_VER #else -# define FMT_MSC_VER 0 +#define FMT_MSC_VER 0 #endif // Check if relaxed C++14 constexpr is supported. // GCC doesn't allow throw in constexpr until version 6 (bug 67371). #ifndef FMT_USE_CONSTEXPR -# define FMT_USE_CONSTEXPR \ +#define FMT_USE_CONSTEXPR \ (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1910 || \ (FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L)) #endif #if FMT_USE_CONSTEXPR -# define FMT_CONSTEXPR constexpr -# define FMT_CONSTEXPR_DECL constexpr +#define FMT_CONSTEXPR constexpr +#define FMT_CONSTEXPR_DECL constexpr #else -# define FMT_CONSTEXPR inline -# define FMT_CONSTEXPR_DECL +#define FMT_CONSTEXPR inline +#define FMT_CONSTEXPR_DECL #endif #ifndef FMT_USE_CONSTEXPR11 -# define FMT_USE_CONSTEXPR11 \ - (FMT_USE_CONSTEXPR || FMT_GCC_VERSION >= 406 || FMT_MSC_VER >= 1900) +#define FMT_USE_CONSTEXPR11 \ + (FMT_USE_CONSTEXPR || FMT_GCC_VERSION >= 406 || FMT_MSC_VER >= 1900) #endif #if FMT_USE_CONSTEXPR11 -# define FMT_CONSTEXPR11 constexpr +#define FMT_CONSTEXPR11 constexpr #else -# define FMT_CONSTEXPR11 +#define FMT_CONSTEXPR11 #endif #ifndef FMT_OVERRIDE -# if 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 +#if 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 -#if FMT_HAS_FEATURE(cxx_explicit_conversions) || \ - FMT_GCC_VERSION >= 405 || FMT_MSC_VER >= 1800 -# define FMT_USE_EXPLICIT 1 -# define FMT_EXPLICIT explicit +#if FMT_HAS_FEATURE(cxx_explicit_conversions) || FMT_GCC_VERSION >= 405 || \ + FMT_MSC_VER >= 1800 +#define FMT_USE_EXPLICIT 1 +#define FMT_EXPLICIT explicit #else -# define FMT_USE_EXPLICIT 0 -# define FMT_EXPLICIT +#define FMT_USE_EXPLICIT 0 +#define FMT_EXPLICIT #endif #ifndef FMT_NULL -# if FMT_HAS_FEATURE(cxx_nullptr) || \ - (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600 -# define FMT_NULL nullptr -# define FMT_USE_NULLPTR 1 -# else -# define FMT_NULL NULL -# endif +#if FMT_HAS_FEATURE(cxx_nullptr) || \ + (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600 +#define FMT_NULL nullptr +#define FMT_USE_NULLPTR 1 +#else +#define FMT_NULL NULL +#endif #endif #ifndef FMT_USE_NULLPTR -# define FMT_USE_NULLPTR 0 +#define FMT_USE_NULLPTR 0 #endif // Check if exceptions are disabled. #ifndef FMT_EXCEPTIONS -# if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \ - FMT_MSC_VER && !_HAS_EXCEPTIONS -# define FMT_EXCEPTIONS 0 -# else -# define FMT_EXCEPTIONS 1 -# endif +#if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \ + FMT_MSC_VER && !_HAS_EXCEPTIONS +#define FMT_EXCEPTIONS 0 +#else +#define FMT_EXCEPTIONS 1 +#endif #endif // Define FMT_USE_NOEXCEPT to make fmt use noexcept (C++11 feature). #ifndef FMT_USE_NOEXCEPT -# define FMT_USE_NOEXCEPT 0 +#define FMT_USE_NOEXCEPT 0 #endif #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900 -# define FMT_DETECTED_NOEXCEPT noexcept -# define FMT_HAS_CXX11_NOEXCEPT 1 +#define FMT_DETECTED_NOEXCEPT noexcept +#define FMT_HAS_CXX11_NOEXCEPT 1 #else -# define FMT_DETECTED_NOEXCEPT throw() -# define FMT_HAS_CXX11_NOEXCEPT 0 +#define FMT_DETECTED_NOEXCEPT throw() +#define FMT_HAS_CXX11_NOEXCEPT 0 #endif #ifndef FMT_NOEXCEPT -# if FMT_EXCEPTIONS || FMT_HAS_CXX11_NOEXCEPT -# define FMT_NOEXCEPT FMT_DETECTED_NOEXCEPT -# else -# define FMT_NOEXCEPT -# endif +#if FMT_EXCEPTIONS || FMT_HAS_CXX11_NOEXCEPT +#define FMT_NOEXCEPT FMT_DETECTED_NOEXCEPT +#else +#define FMT_NOEXCEPT +#endif #endif #ifndef FMT_BEGIN_NAMESPACE -# 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 -# define FMT_INLINE_NAMESPACE namespace -# define FMT_END_NAMESPACE } using namespace v5; } -# endif -# define FMT_BEGIN_NAMESPACE namespace fmt { FMT_INLINE_NAMESPACE v5 { +#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 +#define FMT_INLINE_NAMESPACE namespace +#define FMT_END_NAMESPACE \ + } \ + using namespace v5; \ + } +#endif +#define FMT_BEGIN_NAMESPACE \ + namespace fmt { \ + FMT_INLINE_NAMESPACE v5 { #endif #if !defined(FMT_HEADER_ONLY) && defined(_WIN32) -# ifdef FMT_EXPORT -# define FMT_API __declspec(dllexport) -# elif defined(FMT_SHARED) -# define FMT_API __declspec(dllimport) -# endif +#ifdef FMT_EXPORT +#define FMT_API __declspec(dllexport) +#elif defined(FMT_SHARED) +#define FMT_API __declspec(dllimport) +#endif #endif #ifndef FMT_API -# define FMT_API +#define FMT_API #endif #ifndef FMT_ASSERT -# define FMT_ASSERT(condition, message) assert((condition) && message) +#define FMT_ASSERT(condition, message) assert((condition) && message) #endif // libc++ supports string_view in pre-c++17. -#if (FMT_HAS_INCLUDE() && \ - (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \ +#if (FMT_HAS_INCLUDE() && \ + (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \ (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910) -# include -# define FMT_STRING_VIEW std::basic_string_view -#elif FMT_HAS_INCLUDE() && __cplusplus >= 201402L -# include -# define FMT_STRING_VIEW std::experimental::basic_string_view +#include +#define FMT_STRING_VIEW std::basic_string_view +#elif FMT_HAS_INCLUDE() && __cplusplus >= 201402L +#include +#define FMT_STRING_VIEW std::experimental::basic_string_view #endif // std::result_of is defined in in gcc 4.4. #if FMT_GCC_VERSION && FMT_GCC_VERSION <= 404 -# include +#include #endif FMT_BEGIN_NAMESPACE @@ -199,8 +206,8 @@ struct result_of; template struct result_of { // A workaround for gcc 4.4 that doesn't allow F to be a reference. - typedef typename std::result_of< - typename std::remove_reference::type(Args...)>::type type; + typedef typename std::result_of::type( + Args...)>::type type; }; // Casts nonnegative integer to unsigned. @@ -223,10 +230,12 @@ class basic_buffer { protected: // Don't initialize ptr_ since it is not accessed to save a few cycles. - basic_buffer(std::size_t sz) FMT_NOEXCEPT: size_(sz), capacity_(sz) {} + basic_buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} - basic_buffer(T *p = FMT_NULL, std::size_t sz = 0, std::size_t cap = 0) - FMT_NOEXCEPT: ptr_(p), size_(sz), capacity_(cap) {} + basic_buffer(T *p = FMT_NULL, std::size_t sz = 0, + std::size_t cap = 0) FMT_NOEXCEPT : ptr_(p), + size_(sz), + capacity_(cap) {} /** Sets the buffer data and capacity. */ void set(T *buf_data, std::size_t buf_capacity) FMT_NOEXCEPT { @@ -305,14 +314,14 @@ class container_buffer : public basic_buffer { public: explicit container_buffer(Container &c) - : basic_buffer(c.size()), container_(c) {} + : basic_buffer(c.size()), container_(c) {} }; // Extracts a reference to the container from back_insert_iterator. template inline Container &get_container(std::back_insert_iterator it) { typedef std::back_insert_iterator bi_iterator; - struct accessor: bi_iterator { + struct accessor : bi_iterator { accessor(bi_iterator iter) : bi_iterator(iter) {} using bi_iterator::container; }; @@ -333,7 +342,7 @@ struct no_formatter_error : std::false_type {}; #if FMT_GCC_VERSION && FMT_GCC_VERSION < 405 template -struct is_constructible: std::false_type {}; +struct is_constructible : std::false_type {}; #else template struct is_constructible : std::is_constructible {}; @@ -360,7 +369,8 @@ class basic_string_view { /** Constructs a string reference object from a C string and a size. */ FMT_CONSTEXPR basic_string_view(const Char *s, size_t count) FMT_NOEXCEPT - : data_(s), size_(count) {} + : data_(s), + size_(count) {} /** \rst @@ -369,17 +379,18 @@ class basic_string_view { \endrst */ basic_string_view(const Char *s) - : data_(s), size_(std::char_traits::length(s)) {} + : data_(s), size_(std::char_traits::length(s)) {} /** Constructs a string reference from a ``std::basic_string`` object. */ template - FMT_CONSTEXPR basic_string_view( - const std::basic_string &s) FMT_NOEXCEPT - : data_(s.data()), size_(s.size()) {} + FMT_CONSTEXPR basic_string_view(const std::basic_string &s) + FMT_NOEXCEPT : data_(s.data()), + size_(s.size()) {} #ifdef FMT_STRING_VIEW FMT_CONSTEXPR basic_string_view(FMT_STRING_VIEW s) FMT_NOEXCEPT - : data_(s.data()), size_(s.size()) {} + : data_(s.data()), + size_(s.size()) {} #endif /** Returns a pointer to the string data. */ @@ -451,20 +462,26 @@ typedef basic_string_view wstring_view; \endrst */ template -inline basic_string_view - to_string_view(basic_string_view s) { return s; } +inline basic_string_view to_string_view(basic_string_view s) { + return s; +} template -inline basic_string_view - to_string_view(const std::basic_string &s) { return s; } +inline basic_string_view to_string_view( + const std::basic_string &s) { + return s; +} template -inline basic_string_view to_string_view(const Char *s) { return s; } +inline basic_string_view to_string_view(const Char *s) { + return s; +} #ifdef FMT_STRING_VIEW template -inline basic_string_view - to_string_view(FMT_STRING_VIEW s) { return s; } +inline basic_string_view to_string_view(FMT_STRING_VIEW s) { + return s; +} #endif // A base class for compile-time strings. It is defined in the fmt namespace to @@ -474,11 +491,12 @@ struct compile_string {}; template struct is_compile_string : std::is_base_of {}; -template < - typename S, - typename Enable = typename std::enable_if::value>::type> -FMT_CONSTEXPR basic_string_view - to_string_view(const S &s) { return s; } +template ::value>::type> +FMT_CONSTEXPR basic_string_view to_string_view( + const S &s) { + return s; +} template class basic_format_arg; @@ -489,9 +507,10 @@ class basic_format_args; // A formatter for objects of type T. template struct formatter { - static_assert(internal::no_formatter_error::value, - "don't know how to format the type, include fmt/ostream.h if it provides " - "an operator<< that should be used"); + static_assert( + internal::no_formatter_error::value, + "don't know how to format the type, include fmt/ostream.h if it provides " + "an operator<< that should be used"); // The following functions are not defined intentionally. template @@ -501,19 +520,25 @@ struct formatter { }; template -struct convert_to_int: std::integral_constant< - bool, !std::is_arithmetic::value && std::is_convertible::value> {}; +struct convert_to_int + : std::integral_constant::value && + std::is_convertible::value> {}; namespace internal { -struct dummy_string_view { typedef void char_type; }; +struct dummy_string_view { + typedef void char_type; +}; dummy_string_view to_string_view(...); using fmt::v5::to_string_view; // Specifies whether S is a string type convertible to fmt::basic_string_view. template -struct is_string : std::integral_constant()))>::value> {}; +struct is_string + : std::integral_constant< + bool, !std::is_same()))>::value> { +}; template struct char_t { @@ -528,13 +553,24 @@ template struct named_arg; enum type { - none_type, named_arg_type, + none_type, + named_arg_type, // Integer types should go first, - int_type, uint_type, long_long_type, ulong_long_type, bool_type, char_type, + int_type, + uint_type, + long_long_type, + ulong_long_type, + bool_type, + char_type, last_integer_type = char_type, // followed by floating-point types. - double_type, long_double_type, last_numeric_type = long_double_type, - cstring_type, string_type, pointer_type, custom_type + double_type, + long_double_type, + last_numeric_type = long_double_type, + cstring_type, + string_type, + pointer_type, + custom_type }; FMT_CONSTEXPR bool is_integral(type t) { @@ -609,7 +645,7 @@ class value { } const named_arg_base &as_named_arg() { - return *static_cast*>(pointer); + return *static_cast *>(pointer); } private: @@ -622,7 +658,7 @@ class value { typename Context::template formatter_type::type f; auto &&parse_ctx = ctx.parse_context(); parse_ctx.advance_to(f.parse(parse_ctx)); - ctx.advance_to(f.format(*static_cast(arg), ctx)); + ctx.advance_to(f.format(*static_cast(arg), ctx)); } }; @@ -639,15 +675,17 @@ struct init { template FMT_CONSTEXPR basic_format_arg make_arg(const T &value); -#define FMT_MAKE_VALUE(TAG, ArgType, ValueType) \ - template \ +#define FMT_MAKE_VALUE(TAG, ArgType, ValueType) \ + template \ FMT_CONSTEXPR init make_value(ArgType val) { \ - return static_cast(val); \ + return static_cast(val); \ } -#define FMT_MAKE_VALUE_SAME(TAG, Type) \ - template \ - FMT_CONSTEXPR init make_value(Type val) { return val; } +#define FMT_MAKE_VALUE_SAME(TAG, Type) \ + template \ + FMT_CONSTEXPR init make_value(Type val) { \ + return val; \ + } FMT_MAKE_VALUE(bool_type, bool, int) FMT_MAKE_VALUE(int_type, short, int) @@ -658,14 +696,14 @@ FMT_MAKE_VALUE_SAME(uint_type, unsigned) // To minimize the number of types we need to deal with, long is translated // either to int or to long long depending on its size. typedef std::conditional::type - long_type; -FMT_MAKE_VALUE( - (sizeof(long) == sizeof(int) ? int_type : long_long_type), long, long_type) -typedef std::conditional::type ulong_type; -FMT_MAKE_VALUE( - (sizeof(unsigned long) == sizeof(unsigned) ? uint_type : ulong_long_type), - unsigned long, ulong_type) + long_type; +FMT_MAKE_VALUE((sizeof(long) == sizeof(int) ? int_type : long_long_type), long, + long_type) +typedef std::conditional::type ulong_type; +FMT_MAKE_VALUE((sizeof(unsigned long) == sizeof(unsigned) ? uint_type + : ulong_long_type), + unsigned long, ulong_type) FMT_MAKE_VALUE_SAME(long_long_type, long long) FMT_MAKE_VALUE_SAME(ulong_long_type, unsigned long long) @@ -674,14 +712,20 @@ FMT_MAKE_VALUE(uint_type, unsigned char, unsigned) // This doesn't use FMT_MAKE_VALUE because of ambiguity in gcc 4.4. template -FMT_CONSTEXPR typename std::enable_if< - std::is_same::value, - init>::type make_value(Char val) { return val; } +FMT_CONSTEXPR + typename std::enable_if::value, + init>::type + make_value(Char val) { + return val; +} template -FMT_CONSTEXPR typename std::enable_if< - !std::is_same::value, - init>::type make_value(char val) { return val; } +FMT_CONSTEXPR + typename std::enable_if::value, + init>::type + make_value(char val) { + return val; +} FMT_MAKE_VALUE(double_type, float, double) FMT_MAKE_VALUE_SAME(double_type, double) @@ -689,26 +733,26 @@ FMT_MAKE_VALUE_SAME(long_double_type, long double) // Formatting of wide strings into a narrow buffer and multibyte strings // into a wide buffer is disallowed (https://github.com/fmtlib/fmt/pull/606). -FMT_MAKE_VALUE(cstring_type, typename C::char_type*, - const typename C::char_type*) -FMT_MAKE_VALUE(cstring_type, const typename C::char_type*, - const typename C::char_type*) +FMT_MAKE_VALUE(cstring_type, typename C::char_type *, + const typename C::char_type *) +FMT_MAKE_VALUE(cstring_type, const typename C::char_type *, + const typename C::char_type *) -FMT_MAKE_VALUE(cstring_type, signed char*, const signed char*) -FMT_MAKE_VALUE_SAME(cstring_type, const signed char*) -FMT_MAKE_VALUE(cstring_type, unsigned char*, const unsigned char*) -FMT_MAKE_VALUE_SAME(cstring_type, const unsigned char*) +FMT_MAKE_VALUE(cstring_type, signed char *, const signed char *) +FMT_MAKE_VALUE_SAME(cstring_type, const signed char *) +FMT_MAKE_VALUE(cstring_type, unsigned char *, const unsigned char *) +FMT_MAKE_VALUE_SAME(cstring_type, const unsigned char *) FMT_MAKE_VALUE_SAME(string_type, basic_string_view) FMT_MAKE_VALUE(string_type, typename basic_string_view::type, basic_string_view) -FMT_MAKE_VALUE(string_type, const std::basic_string&, +FMT_MAKE_VALUE(string_type, const std::basic_string &, basic_string_view) -FMT_MAKE_VALUE(pointer_type, void*, const void*) -FMT_MAKE_VALUE_SAME(pointer_type, const void*) +FMT_MAKE_VALUE(pointer_type, void *, const void *) +FMT_MAKE_VALUE_SAME(pointer_type, const void *) #if FMT_USE_NULLPTR -FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*) +FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void *) #endif // Formatting of arbitrary pointers is disallowed. If you want to output a @@ -717,51 +761,58 @@ FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*) // iostreams. template typename std::enable_if::value>::type - make_value(const T *) { +make_value(const T *) { static_assert(!sizeof(T), "formatting of non-void pointers is disallowed"); } template -inline typename std::enable_if< - std::is_enum::value && convert_to_int::value, - init>::type - make_value(const T &val) { return static_cast(val); } +inline + typename std::enable_if::value && + convert_to_int::value, + init>::type + make_value(const T &val) { + return static_cast(val); +} template inline typename std::enable_if< is_constructible, T>::value && - !internal::is_string::value, + !internal::is_string::value, init, string_type>>::type - make_value(const T &val) { return basic_string_view(val); } +make_value(const T &val) { + return basic_string_view(val); +} template inline typename std::enable_if< !convert_to_int::value && !std::is_same::value && - !std::is_convertible>::value && - !is_constructible, T>::value && - !internal::is_string::value, + !std::is_convertible>::value && + !is_constructible, T>::value && + !internal::is_string::value, // Implicit conversion to std::string is not handled here because it's // unsafe: https://github.com/fmtlib/fmt/issues/729 init>::type - make_value(const T &val) { return val; } +make_value(const T &val) { + return val; +} template -init - make_value(const named_arg &val) { +init make_value( + const named_arg &val) { basic_format_arg arg = make_arg(val.value); std::memcpy(val.data, &arg, sizeof(arg)); - return static_cast(&val); + return static_cast(&val); } template FMT_CONSTEXPR11 typename std::enable_if< - internal::is_string::value, - init, string_type>>::type - make_value(const S &val) { + internal::is_string::value, + init, string_type>>::type +make_value(const S &val) { // Handle adapted strings. - static_assert(std::is_same< - typename C::char_type, typename internal::char_t::type>::value, - "mismatch between char-types of context and argument"); + static_assert(std::is_same::type>::value, + "mismatch between char-types of context and argument"); return to_string_view(val); } @@ -782,12 +833,12 @@ class basic_format_arg { internal::type type_; template - friend FMT_CONSTEXPR basic_format_arg - internal::make_arg(const T &value); + friend FMT_CONSTEXPR basic_format_arg internal::make_arg( + const T &value); template friend FMT_CONSTEXPR typename internal::result_of::type - visit_format_arg(Visitor &&vis, const basic_format_arg &arg); + visit_format_arg(Visitor &&vis, const basic_format_arg &arg); friend class basic_format_args; friend class internal::arg_map; @@ -797,7 +848,7 @@ class basic_format_arg { public: class handle { public: - explicit handle(internal::custom_value custom): custom_(custom) {} + explicit handle(internal::custom_value custom) : custom_(custom) {} void format(Context &ctx) const { custom_.format(custom_.value, ctx); } @@ -827,47 +878,47 @@ struct monostate {}; \endrst */ template -FMT_CONSTEXPR typename internal::result_of::type - visit_format_arg(Visitor &&vis, const basic_format_arg &arg) { +FMT_CONSTEXPR typename internal::result_of::type visit_format_arg( + Visitor &&vis, const basic_format_arg &arg) { typedef typename Context::char_type char_type; switch (arg.type_) { - case internal::none_type: - break; - case internal::named_arg_type: - FMT_ASSERT(false, "invalid argument type"); - break; - case internal::int_type: - return vis(arg.value_.int_value); - case internal::uint_type: - return vis(arg.value_.uint_value); - case internal::long_long_type: - return vis(arg.value_.long_long_value); - case internal::ulong_long_type: - return vis(arg.value_.ulong_long_value); - case internal::bool_type: - return vis(arg.value_.int_value != 0); - case internal::char_type: - return vis(static_cast(arg.value_.int_value)); - case internal::double_type: - return vis(arg.value_.double_value); - case internal::long_double_type: - return vis(arg.value_.long_double_value); - case internal::cstring_type: - return vis(arg.value_.string.value); - case internal::string_type: - return vis(basic_string_view( - arg.value_.string.value, arg.value_.string.size)); - case internal::pointer_type: - return vis(arg.value_.pointer); - case internal::custom_type: - return vis(typename basic_format_arg::handle(arg.value_.custom)); + case internal::none_type: + break; + case internal::named_arg_type: + FMT_ASSERT(false, "invalid argument type"); + break; + case internal::int_type: + return vis(arg.value_.int_value); + case internal::uint_type: + return vis(arg.value_.uint_value); + case internal::long_long_type: + return vis(arg.value_.long_long_value); + case internal::ulong_long_type: + return vis(arg.value_.ulong_long_value); + case internal::bool_type: + return vis(arg.value_.int_value != 0); + case internal::char_type: + return vis(static_cast(arg.value_.int_value)); + case internal::double_type: + return vis(arg.value_.double_value); + case internal::long_double_type: + return vis(arg.value_.long_double_value); + case internal::cstring_type: + return vis(arg.value_.string.value); + case internal::string_type: + return vis(basic_string_view(arg.value_.string.value, + arg.value_.string.size)); + case internal::pointer_type: + return vis(arg.value_.pointer); + case internal::custom_type: + return vis(typename basic_format_arg::handle(arg.value_.custom)); } return vis(monostate()); } template -FMT_CONSTEXPR typename internal::result_of::type - visit(Visitor &&vis, const basic_format_arg &arg) { +FMT_CONSTEXPR typename internal::result_of::type visit( + Visitor &&vis, const basic_format_arg &arg) { return visit_format_arg(std::forward(vis), arg); } @@ -883,9 +934,9 @@ class basic_parse_context : private ErrorHandler { typedef Char char_type; typedef typename basic_string_view::iterator iterator; - explicit FMT_CONSTEXPR basic_parse_context( - basic_string_view format_str, ErrorHandler eh = ErrorHandler()) - : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {} + explicit FMT_CONSTEXPR basic_parse_context(basic_string_view format_str, + ErrorHandler eh = ErrorHandler()) + : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {} // Returns an iterator to the beginning of the format string range being // parsed. @@ -955,7 +1006,7 @@ class arg_map { public: arg_map() : map_(FMT_NULL), size_(0) {} void init(const basic_format_args &args); - ~arg_map() { delete [] map_; } + ~arg_map() { delete[] map_; } basic_format_arg find(basic_string_view name) const { // The list is unsorted, so just return the first matching name. @@ -1001,7 +1052,7 @@ class context_base { context_base(OutputIt out, basic_string_view format_str, basic_format_args ctx_args, locale_ref loc = locale_ref()) - : parse_context_(format_str), out_(out), args_(ctx_args), loc_(loc) {} + : parse_context_(format_str), out_(out), args_(ctx_args), loc_(loc) {} // Returns the argument with specified index. format_arg do_get_arg(unsigned arg_id) { @@ -1014,13 +1065,13 @@ class context_base { // Checks if manual indexing is used and returns the argument with // specified index. format_arg get_arg(unsigned arg_id) { - return this->parse_context().check_arg_id(arg_id) ? - this->do_get_arg(arg_id) : format_arg(); + return this->parse_context().check_arg_id(arg_id) ? this->do_get_arg(arg_id) + : format_arg(); } public: basic_parse_context &parse_context() { return parse_context_; } - basic_format_args args() const { return args_; } // DEPRECATED! + basic_format_args args() const { return args_; } // DEPRECATED! basic_format_arg arg(unsigned id) const { return args_.get(id); } internal::error_handler error_handler() { @@ -1042,12 +1093,14 @@ class context_base { template struct get_type { typedef decltype(make_value( - declval::type&>())) value_type; + declval::type &>())) value_type; static const type value = value_type::type_tag; }; template -FMT_CONSTEXPR11 unsigned long long get_types() { return 0; } +FMT_CONSTEXPR11 unsigned long long get_types() { + return 0; +} template FMT_CONSTEXPR11 unsigned long long get_types() { @@ -1063,30 +1116,32 @@ FMT_CONSTEXPR basic_format_arg make_arg(const T &value) { } template -inline typename std::enable_if>::type - make_arg(const T &value) { +inline typename std::enable_if>::type make_arg( + const T &value) { return make_value(value); } template inline typename std::enable_if>::type - make_arg(const T &value) { +make_arg(const T &value) { return make_arg(value); } } // namespace internal // Formatting context. template -class basic_format_context : - public internal::context_base< - OutputIt, basic_format_context, Char> { +class basic_format_context + : public internal::context_base< + OutputIt, basic_format_context, Char> { public: /** The character type for the output. */ typedef Char char_type; // using formatter_type = formatter; template - struct formatter_type { typedef formatter type; }; + struct formatter_type { + typedef formatter type; + }; private: internal::arg_map map_; @@ -1108,7 +1163,7 @@ class basic_format_context : basic_format_context(OutputIt out, basic_string_view format_str, basic_format_args ctx_args, internal::locale_ref loc = internal::locale_ref()) - : base(out, format_str, ctx_args, loc) {} + : base(out, format_str, ctx_args, loc) {} format_arg next_arg() { return this->do_get_arg(this->parse_context().next_arg_id()); @@ -1123,7 +1178,8 @@ class basic_format_context : template struct buffer_context { typedef basic_format_context< - std::back_insert_iterator>, Char> type; + std::back_insert_iterator>, Char> + type; }; typedef buffer_context::type format_context; typedef buffer_context::type wformat_context; @@ -1135,7 +1191,7 @@ typedef buffer_context::type wformat_context; such as `~fmt::vformat`. \endrst */ -template +template class format_arg_store { private: static const size_t NUM_ARGS = sizeof...(Args); @@ -1143,20 +1199,19 @@ class format_arg_store { // Packed is a macro on MinGW so use IS_PACKED instead. static const bool IS_PACKED = NUM_ARGS < internal::max_packed_args; - typedef typename std::conditional, basic_format_arg>::type value_type; + typedef typename std::conditional, + basic_format_arg>::type value_type; // If the arguments are not packed, add one more element to mark the end. static const size_t DATA_SIZE = - NUM_ARGS + (IS_PACKED && NUM_ARGS != 0 ? 0 : 1); + NUM_ARGS + (IS_PACKED && NUM_ARGS != 0 ? 0 : 1); value_type data_[DATA_SIZE]; friend class basic_format_args; static FMT_CONSTEXPR11 unsigned long long get_types() { - return IS_PACKED ? - internal::get_types() : - internal::is_unpacked_bit | NUM_ARGS; + return IS_PACKED ? internal::get_types() + : internal::is_unpacked_bit | NUM_ARGS; } public: @@ -1170,18 +1225,18 @@ class format_arg_store { (FMT_MSC_VER && FMT_MSC_VER <= 1800) // Workaround array initialization issues in gcc <= 4.5 and MSVC <= 2013. format_arg_store(const Args &... args) { - value_type init[DATA_SIZE] = - {internal::make_arg(args)...}; + value_type init[DATA_SIZE] = { + internal::make_arg(args)...}; std::memcpy(data_, init, sizeof(init)); } #else format_arg_store(const Args &... args) - : data_{internal::make_arg(args)...} {} + : data_{internal::make_arg(args)...} {} #endif }; #if !FMT_USE_CONSTEXPR11 -template +template const unsigned long long format_arg_store::TYPES = get_types(); #endif @@ -1193,16 +1248,18 @@ const unsigned long long format_arg_store::TYPES = can be omitted in which case it defaults to `~fmt::context`. \endrst */ -template -inline format_arg_store - make_format_args(const Args &... args) { return {args...}; } +template +inline format_arg_store make_format_args( + const Args &... args) { + return {args...}; +} /** Formatting arguments. */ template class basic_format_args { public: typedef unsigned size_type; - typedef basic_format_arg format_arg; + typedef basic_format_arg format_arg; private: // To reduce compiled code size per formatting function call, types of first @@ -1222,8 +1279,8 @@ class basic_format_args { typename internal::type type(unsigned index) const { unsigned shift = index * 4; - return static_cast( - (types_ & (0xfull << shift)) >> shift); + return static_cast((types_ & (0xfull << shift)) >> + shift); } friend class internal::arg_map; @@ -1259,7 +1316,7 @@ class basic_format_args { */ template basic_format_args(const format_arg_store &store) - : types_(static_cast(store.TYPES)) { + : types_(static_cast(store.TYPES)) { set_data(store.data_); } @@ -1269,7 +1326,7 @@ class basic_format_args { \endrst */ basic_format_args(const format_arg *args, size_type count) - : types_(internal::is_unpacked_bit | count) { + : types_(internal::is_unpacked_bit | count) { set_data(args); } @@ -1284,38 +1341,38 @@ class basic_format_args { size_type max_size() const { unsigned long long max_packed = internal::max_packed_args; return static_cast( - is_packed() ? max_packed : types_ & ~internal::is_unpacked_bit); + is_packed() ? max_packed : types_ & ~internal::is_unpacked_bit); } }; /** An alias to ``basic_format_args``. */ // It is a separate type rather than a typedef to make symbols readable. struct format_args : basic_format_args { - template + template format_args(Args &&... arg) - : basic_format_args(std::forward(arg)...) {} + : basic_format_args(std::forward(arg)...) {} }; struct wformat_args : basic_format_args { - template + template wformat_args(Args &&... arg) - : basic_format_args(std::forward(arg)...) {} + : basic_format_args(std::forward(arg)...) {} }; #define FMT_ENABLE_IF_T(B, T) typename std::enable_if::type #ifndef FMT_USE_ALIAS_TEMPLATES -# define FMT_USE_ALIAS_TEMPLATES FMT_HAS_FEATURE(cxx_alias_templates) +#define FMT_USE_ALIAS_TEMPLATES FMT_HAS_FEATURE(cxx_alias_templates) #endif #if FMT_USE_ALIAS_TEMPLATES /** String's character type. */ template -using char_t = FMT_ENABLE_IF_T( - internal::is_string::value, typename internal::char_t::type); +using char_t = FMT_ENABLE_IF_T(internal::is_string::value, + typename internal::char_t::type); #define FMT_CHAR(S) fmt::char_t #else template -struct char_t : std::enable_if< - internal::is_string::value, typename internal::char_t::type> {}; +struct char_t : std::enable_if::value, + typename internal::char_t::type> {}; #define FMT_CHAR(S) typename char_t::type #endif @@ -1325,8 +1382,8 @@ struct named_arg_base { basic_string_view name; // Serialized value. - mutable char data[ - sizeof(basic_format_arg::type>)]; + mutable char + data[sizeof(basic_format_arg::type>)]; named_arg_base(basic_string_view nm) : name(nm) {} @@ -1343,23 +1400,23 @@ struct named_arg : named_arg_base { const T &value; named_arg(basic_string_view name, const T &val) - : named_arg_base(name), value(val) {} + : named_arg_base(name), value(val) {} }; template inline typename std::enable_if::value>::type - check_format_string(const S &) {} +check_format_string(const S &) {} template -typename std::enable_if::value>::type - check_format_string(S); +typename std::enable_if::value>::type check_format_string( + S); template -struct checked_args : format_arg_store< - typename buffer_context::type, Args...> { +struct checked_args + : format_arg_store::type, Args...> { typedef typename buffer_context::type context; - checked_args(const S &format_str, const Args &... args): - format_arg_store(args...) { + checked_args(const S &format_str, const Args &... args) + : format_arg_store(args...) { internal::check_format_string(format_str); } @@ -1368,14 +1425,14 @@ struct checked_args : format_arg_store< template std::basic_string vformat( - basic_string_view format_str, - basic_format_args::type> args); + basic_string_view format_str, + basic_format_args::type> args); template typename buffer_context::type::iterator vformat_to( - internal::basic_buffer &buf, basic_string_view format_str, - basic_format_args::type> args); -} + internal::basic_buffer &buf, basic_string_view format_str, + basic_format_args::type> args); +} // namespace internal /** \rst @@ -1401,33 +1458,31 @@ template void arg(S, internal::named_arg) = delete; template -struct is_contiguous: std::false_type {}; +struct is_contiguous : std::false_type {}; template -struct is_contiguous >: std::true_type {}; +struct is_contiguous> : std::true_type {}; template -struct is_contiguous >: std::true_type {}; +struct is_contiguous> : std::true_type {}; /** Formats a string and writes the output to ``out``. */ template -typename std::enable_if< - is_contiguous::value, std::back_insert_iterator>::type - vformat_to( - std::back_insert_iterator out, - const S &format_str, - basic_format_args::type> args) { +typename std::enable_if::value, + std::back_insert_iterator>::type +vformat_to(std::back_insert_iterator out, const S &format_str, + basic_format_args::type> args) { internal::container_buffer buf(internal::get_container(out)); internal::vformat_to(buf, to_string_view(format_str), args); return out; } template -inline typename std::enable_if< - is_contiguous::value && internal::is_string::value, - std::back_insert_iterator>::type - format_to(std::back_insert_iterator out, const S &format_str, - const Args &... args) { +inline typename std::enable_if::value && + internal::is_string::value, + std::back_insert_iterator>::type +format_to(std::back_insert_iterator out, const S &format_str, + const Args &... args) { internal::checked_args ca(format_str, args...); return vformat_to(out, to_string_view(format_str), *ca); } @@ -1450,11 +1505,11 @@ inline std::basic_string vformat( \endrst */ template -inline std::basic_string format( - const S &format_str, const Args &... args) { +inline std::basic_string format(const S &format_str, + const Args &... args) { return internal::vformat( - to_string_view(format_str), - *internal::checked_args(format_str, args...)); + to_string_view(format_str), + *internal::checked_args(format_str, args...)); } FMT_API void vprint(std::FILE *f, string_view format_str, format_args args); diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 9b739635..eb5e3fb8 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -10,47 +10,46 @@ #include "format.h" -#include - #include #include #include #include #include #include // for std::ptrdiff_t +#include #include // for std::memmove #if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) -# include +#include #endif #if FMT_USE_WINDOWS_H -# if !defined(FMT_HEADER_ONLY) && !defined(WIN32_LEAN_AND_MEAN) -# define WIN32_LEAN_AND_MEAN -# endif -# if defined(NOMINMAX) || defined(FMT_WIN_MINMAX) -# include -# else -# define NOMINMAX -# include -# undef NOMINMAX -# endif +#if !defined(FMT_HEADER_ONLY) && !defined(WIN32_LEAN_AND_MEAN) +#define WIN32_LEAN_AND_MEAN +#endif +#if defined(NOMINMAX) || defined(FMT_WIN_MINMAX) +#include +#else +#define NOMINMAX +#include +#undef NOMINMAX +#endif #endif #if FMT_EXCEPTIONS -# define FMT_TRY try -# define FMT_CATCH(x) catch (x) +#define FMT_TRY try +#define FMT_CATCH(x) catch (x) #else -# define FMT_TRY if (true) -# define FMT_CATCH(x) if (false) +#define FMT_TRY if (true) +#define FMT_CATCH(x) if (false) #endif #ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable: 4127) // conditional expression is constant -# pragma warning(disable: 4702) // unreachable code +#pragma warning(push) +#pragma warning(disable : 4127) // conditional expression is constant +#pragma warning(disable : 4702) // unreachable code // Disable deprecation warning for strerror. The latter is not called but // MSVC fails to detect it. -# pragma warning(disable: 4996) +#pragma warning(disable : 4996) #endif // Dummy implementations of strerror_r and strerror_s called if corresponding @@ -67,7 +66,7 @@ FMT_BEGIN_NAMESPACE namespace { #ifndef _MSC_VER -# define FMT_SNPRINTF snprintf +#define FMT_SNPRINTF snprintf #else // _MSC_VER inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) { va_list args; @@ -76,14 +75,14 @@ inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) { va_end(args); return result; } -# define FMT_SNPRINTF fmt_snprintf +#define FMT_SNPRINTF fmt_snprintf #endif // _MSC_VER #if defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT) -# define FMT_SWPRINTF snwprintf +#define FMT_SWPRINTF snwprintf #else -# define FMT_SWPRINTF swprintf -#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT) +#define FMT_SWPRINTF swprintf +#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT) typedef void (*FormatFunc)(internal::buffer &, int, string_view); @@ -96,8 +95,8 @@ typedef void (*FormatFunc)(internal::buffer &, int, string_view); // ERANGE - buffer is not large enough to store the error message // other - failure // Buffer should be at least of size 1. -int safe_strerror( - int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT { +int safe_strerror(int error_code, char *&buffer, + std::size_t buffer_size) FMT_NOEXCEPT { FMT_ASSERT(buffer != FMT_NULL && buffer_size != 0, "invalid buffer"); class dispatcher { @@ -132,8 +131,8 @@ int safe_strerror( // Fallback to strerror_s when strerror_r is not available. int fallback(int result) { // If the buffer is full then the message is probably truncated. - return result == 0 && strlen(buffer_) == buffer_size_ - 1 ? - ERANGE : result; + return result == 0 && strlen(buffer_) == buffer_size_ - 1 ? ERANGE + : result; } #if !FMT_MSC_VER @@ -147,11 +146,9 @@ int safe_strerror( public: dispatcher(int err_code, char *&buf, std::size_t buf_size) - : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {} + : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {} - int run() { - return handle(strerror_r(error_code_, buffer_, buffer_size_)); - } + int run() { return handle(strerror_r(error_code_, buffer_, buffer_size_)); } }; return dispatcher(error_code, buffer, buffer_size).run(); } @@ -215,15 +212,15 @@ locale_ref::locale_ref(const Locale &loc) : locale_(&loc) { template Locale locale_ref::get() const { static_assert(std::is_same::value, ""); - return locale_ ? *static_cast(locale_) : std::locale(); + return locale_ ? *static_cast(locale_) : std::locale(); } template FMT_FUNC Char thousands_sep_impl(locale_ref loc) { - return std::use_facet >( - loc.get()).thousands_sep(); -} + return std::use_facet>(loc.get()) + .thousands_sep(); } +} // namespace internal #else template FMT_FUNC Char internal::thousands_sep_impl(locale_ref) { @@ -231,8 +228,8 @@ FMT_FUNC Char internal::thousands_sep_impl(locale_ref) { } #endif -FMT_FUNC void system_error::init( - int err_code, string_view format_str, format_args args) { +FMT_FUNC void system_error::init(int err_code, string_view format_str, + format_args args) { error_code_ = err_code; memory_buffer buffer; format_system_error(buffer, err_code, vformat(format_str, args)); @@ -242,20 +239,19 @@ FMT_FUNC void system_error::init( namespace internal { template -int char_traits::format_float( - char *buf, std::size_t size, const char *format, int precision, T value) { - return precision < 0 ? - FMT_SNPRINTF(buf, size, format, value) : - FMT_SNPRINTF(buf, size, format, precision, value); +int char_traits::format_float(char *buf, std::size_t size, + const char *format, int precision, + T value) { + return precision < 0 ? FMT_SNPRINTF(buf, size, format, value) + : FMT_SNPRINTF(buf, size, format, precision, value); } template -int char_traits::format_float( - wchar_t *buf, std::size_t size, const wchar_t *format, int precision, - T value) { - return precision < 0 ? - FMT_SWPRINTF(buf, size, format, value) : - FMT_SWPRINTF(buf, size, format, precision, value); +int char_traits::format_float(wchar_t *buf, std::size_t size, + const wchar_t *format, int precision, + T value) { + return precision < 0 ? FMT_SWPRINTF(buf, size, format, value) + : FMT_SWPRINTF(buf, size, format, precision, value); } template @@ -266,88 +262,79 @@ const char basic_data::DIGITS[] = "6061626364656667686970717273747576777879" "8081828384858687888990919293949596979899"; -#define FMT_POWERS_OF_10(factor) \ - factor * 10, \ - factor * 100, \ - factor * 1000, \ - factor * 10000, \ - factor * 100000, \ - factor * 1000000, \ - factor * 10000000, \ - factor * 100000000, \ - factor * 1000000000 +#define FMT_POWERS_OF_10(factor) \ + factor * 10, factor * 100, factor * 1000, factor * 10000, factor * 100000, \ + factor * 1000000, factor * 10000000, factor * 100000000, \ + factor * 1000000000 template -const uint32_t basic_data::POWERS_OF_10_32[] = { - 1, FMT_POWERS_OF_10(1) -}; +const uint32_t basic_data::POWERS_OF_10_32[] = {1, FMT_POWERS_OF_10(1)}; template -const uint32_t basic_data::ZERO_OR_POWERS_OF_10_32[] = { - 0, FMT_POWERS_OF_10(1) -}; +const uint32_t basic_data::ZERO_OR_POWERS_OF_10_32[] = {0, + FMT_POWERS_OF_10(1)}; template const uint64_t basic_data::ZERO_OR_POWERS_OF_10_64[] = { - 0, - FMT_POWERS_OF_10(1), - FMT_POWERS_OF_10(1000000000ull), - 10000000000000000000ull -}; + 0, FMT_POWERS_OF_10(1), FMT_POWERS_OF_10(1000000000ull), + 10000000000000000000ull}; // Normalized 64-bit significands of pow(10, k), for k = -348, -340, ..., 340. // These are generated by support/compute-powers.py. template const uint64_t basic_data::POW10_SIGNIFICANDS[] = { - 0xfa8fd5a0081c0288, 0xbaaee17fa23ebf76, 0x8b16fb203055ac76, - 0xcf42894a5dce35ea, 0x9a6bb0aa55653b2d, 0xe61acf033d1a45df, - 0xab70fe17c79ac6ca, 0xff77b1fcbebcdc4f, 0xbe5691ef416bd60c, - 0x8dd01fad907ffc3c, 0xd3515c2831559a83, 0x9d71ac8fada6c9b5, - 0xea9c227723ee8bcb, 0xaecc49914078536d, 0x823c12795db6ce57, - 0xc21094364dfb5637, 0x9096ea6f3848984f, 0xd77485cb25823ac7, - 0xa086cfcd97bf97f4, 0xef340a98172aace5, 0xb23867fb2a35b28e, - 0x84c8d4dfd2c63f3b, 0xc5dd44271ad3cdba, 0x936b9fcebb25c996, - 0xdbac6c247d62a584, 0xa3ab66580d5fdaf6, 0xf3e2f893dec3f126, - 0xb5b5ada8aaff80b8, 0x87625f056c7c4a8b, 0xc9bcff6034c13053, - 0x964e858c91ba2655, 0xdff9772470297ebd, 0xa6dfbd9fb8e5b88f, - 0xf8a95fcf88747d94, 0xb94470938fa89bcf, 0x8a08f0f8bf0f156b, - 0xcdb02555653131b6, 0x993fe2c6d07b7fac, 0xe45c10c42a2b3b06, - 0xaa242499697392d3, 0xfd87b5f28300ca0e, 0xbce5086492111aeb, - 0x8cbccc096f5088cc, 0xd1b71758e219652c, 0x9c40000000000000, - 0xe8d4a51000000000, 0xad78ebc5ac620000, 0x813f3978f8940984, - 0xc097ce7bc90715b3, 0x8f7e32ce7bea5c70, 0xd5d238a4abe98068, - 0x9f4f2726179a2245, 0xed63a231d4c4fb27, 0xb0de65388cc8ada8, - 0x83c7088e1aab65db, 0xc45d1df942711d9a, 0x924d692ca61be758, - 0xda01ee641a708dea, 0xa26da3999aef774a, 0xf209787bb47d6b85, - 0xb454e4a179dd1877, 0x865b86925b9bc5c2, 0xc83553c5c8965d3d, - 0x952ab45cfa97a0b3, 0xde469fbd99a05fe3, 0xa59bc234db398c25, - 0xf6c69a72a3989f5c, 0xb7dcbf5354e9bece, 0x88fcf317f22241e2, - 0xcc20ce9bd35c78a5, 0x98165af37b2153df, 0xe2a0b5dc971f303a, - 0xa8d9d1535ce3b396, 0xfb9b7cd9a4a7443c, 0xbb764c4ca7a44410, - 0x8bab8eefb6409c1a, 0xd01fef10a657842c, 0x9b10a4e5e9913129, - 0xe7109bfba19c0c9d, 0xac2820d9623bf429, 0x80444b5e7aa7cf85, - 0xbf21e44003acdd2d, 0x8e679c2f5e44ff8f, 0xd433179d9c8cb841, - 0x9e19db92b4e31ba9, 0xeb96bf6ebadf77d9, 0xaf87023b9bf0ee6b, + 0xfa8fd5a0081c0288, 0xbaaee17fa23ebf76, 0x8b16fb203055ac76, + 0xcf42894a5dce35ea, 0x9a6bb0aa55653b2d, 0xe61acf033d1a45df, + 0xab70fe17c79ac6ca, 0xff77b1fcbebcdc4f, 0xbe5691ef416bd60c, + 0x8dd01fad907ffc3c, 0xd3515c2831559a83, 0x9d71ac8fada6c9b5, + 0xea9c227723ee8bcb, 0xaecc49914078536d, 0x823c12795db6ce57, + 0xc21094364dfb5637, 0x9096ea6f3848984f, 0xd77485cb25823ac7, + 0xa086cfcd97bf97f4, 0xef340a98172aace5, 0xb23867fb2a35b28e, + 0x84c8d4dfd2c63f3b, 0xc5dd44271ad3cdba, 0x936b9fcebb25c996, + 0xdbac6c247d62a584, 0xa3ab66580d5fdaf6, 0xf3e2f893dec3f126, + 0xb5b5ada8aaff80b8, 0x87625f056c7c4a8b, 0xc9bcff6034c13053, + 0x964e858c91ba2655, 0xdff9772470297ebd, 0xa6dfbd9fb8e5b88f, + 0xf8a95fcf88747d94, 0xb94470938fa89bcf, 0x8a08f0f8bf0f156b, + 0xcdb02555653131b6, 0x993fe2c6d07b7fac, 0xe45c10c42a2b3b06, + 0xaa242499697392d3, 0xfd87b5f28300ca0e, 0xbce5086492111aeb, + 0x8cbccc096f5088cc, 0xd1b71758e219652c, 0x9c40000000000000, + 0xe8d4a51000000000, 0xad78ebc5ac620000, 0x813f3978f8940984, + 0xc097ce7bc90715b3, 0x8f7e32ce7bea5c70, 0xd5d238a4abe98068, + 0x9f4f2726179a2245, 0xed63a231d4c4fb27, 0xb0de65388cc8ada8, + 0x83c7088e1aab65db, 0xc45d1df942711d9a, 0x924d692ca61be758, + 0xda01ee641a708dea, 0xa26da3999aef774a, 0xf209787bb47d6b85, + 0xb454e4a179dd1877, 0x865b86925b9bc5c2, 0xc83553c5c8965d3d, + 0x952ab45cfa97a0b3, 0xde469fbd99a05fe3, 0xa59bc234db398c25, + 0xf6c69a72a3989f5c, 0xb7dcbf5354e9bece, 0x88fcf317f22241e2, + 0xcc20ce9bd35c78a5, 0x98165af37b2153df, 0xe2a0b5dc971f303a, + 0xa8d9d1535ce3b396, 0xfb9b7cd9a4a7443c, 0xbb764c4ca7a44410, + 0x8bab8eefb6409c1a, 0xd01fef10a657842c, 0x9b10a4e5e9913129, + 0xe7109bfba19c0c9d, 0xac2820d9623bf429, 0x80444b5e7aa7cf85, + 0xbf21e44003acdd2d, 0x8e679c2f5e44ff8f, 0xd433179d9c8cb841, + 0x9e19db92b4e31ba9, 0xeb96bf6ebadf77d9, 0xaf87023b9bf0ee6b, }; // Binary exponents of pow(10, k), for k = -348, -340, ..., 340, corresponding // to significands above. template const int16_t basic_data::POW10_EXPONENTS[] = { - -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980, -954, - -927, -901, -874, -847, -821, -794, -768, -741, -715, -688, -661, - -635, -608, -582, -555, -529, -502, -475, -449, -422, -396, -369, - -343, -316, -289, -263, -236, -210, -183, -157, -130, -103, -77, - -50, -24, 3, 30, 56, 83, 109, 136, 162, 189, 216, - 242, 269, 295, 322, 348, 375, 402, 428, 455, 481, 508, - 534, 561, 588, 614, 641, 667, 694, 720, 747, 774, 800, - 827, 853, 880, 907, 933, 960, 986, 1013, 1039, 1066 -}; + -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980, -954, + -927, -901, -874, -847, -821, -794, -768, -741, -715, -688, -661, + -635, -608, -582, -555, -529, -502, -475, -449, -422, -396, -369, + -343, -316, -289, -263, -236, -210, -183, -157, -130, -103, -77, + -50, -24, 3, 30, 56, 83, 109, 136, 162, 189, 216, + 242, 269, 295, 322, 348, 375, 402, 428, 455, 481, 508, + 534, 561, 588, 614, 641, 667, 694, 720, 747, 774, 800, + 827, 853, 880, 907, 933, 960, 986, 1013, 1039, 1066}; -template const char basic_data::FOREGROUND_COLOR[] = "\x1b[38;2;"; -template const char basic_data::BACKGROUND_COLOR[] = "\x1b[48;2;"; -template const char basic_data::RESET_COLOR[] = "\x1b[0m"; -template const wchar_t basic_data::WRESET_COLOR[] = L"\x1b[0m"; +template +const char basic_data::FOREGROUND_COLOR[] = "\x1b[38;2;"; +template +const char basic_data::BACKGROUND_COLOR[] = "\x1b[48;2;"; +template +const char basic_data::RESET_COLOR[] = "\x1b[0m"; +template +const wchar_t basic_data::WRESET_COLOR[] = L"\x1b[0m"; // A handmade floating-point number f * pow(2, e). class fp { @@ -356,23 +343,23 @@ class fp { // All sizes are in bits. static FMT_CONSTEXPR_DECL const int char_size = - std::numeric_limits::digits; + std::numeric_limits::digits; // Subtract 1 to account for an implicit most significant bit in the // normalized form. static FMT_CONSTEXPR_DECL const int double_significand_size = - std::numeric_limits::digits - 1; + std::numeric_limits::digits - 1; static FMT_CONSTEXPR_DECL const uint64_t implicit_bit = - 1ull << double_significand_size; + 1ull << double_significand_size; public: significand_type f; int e; static FMT_CONSTEXPR_DECL const int significand_size = - sizeof(significand_type) * char_size; + sizeof(significand_type) * char_size; - fp(): f(0), e(0) {} - fp(uint64_t f_val, int e_val): f(f_val), e(e_val) {} + fp() : f(0), e(0) {} + fp(uint64_t f_val, int e_val) : f(f_val), e(e_val) {} // Constructs fp from an IEEE754 double. It is a template to prevent compile // errors on platforms where double is not IEEE754. @@ -382,7 +369,7 @@ class fp { typedef std::numeric_limits limits; const int double_size = static_cast(sizeof(Double) * char_size); const int exponent_size = - double_size - double_significand_size - 1; // -1 for sign + double_size - double_significand_size - 1; // -1 for sign const uint64_t significand_mask = implicit_bit - 1; const uint64_t exponent_mask = (~0ull >> 1) & ~significand_mask; const int exponent_bias = (1 << exponent_size) - limits::max_exponent - 1; @@ -416,8 +403,8 @@ class fp { // (lower) or successor (upper). The upper boundary is normalized and lower // has the same exponent but may be not normalized. void compute_boundaries(fp &lower, fp &upper) const { - lower = f == implicit_bit ? - fp((f << 2) - 1, e - 2) : fp((f << 1) - 1, e - 1); + lower = + f == implicit_bit ? fp((f << 2) - 1, e - 2) : fp((f << 1) - 1, e - 1); upper = fp((f << 1) + 1, e - 1); upper.normalize<1>(); // 1 is to account for the exponent shift above. lower.f <<= lower.e - upper.e; @@ -432,7 +419,8 @@ inline fp operator-(fp x, fp y) { } // Computes an fp number r with r.f = x.f * y.f / pow(2, 64) rounded to nearest -// with half-up tie breaking, r.e = x.e + y.e + 64. Result may not be normalized. +// with half-up tie breaking, r.e = x.e + y.e + 64. Result may not be +// normalized. FMT_API fp operator*(fp x, fp y); // Returns cached power (of 10) c_k = c_k.f * pow(2, c_k.e) such that its @@ -452,8 +440,8 @@ FMT_FUNC fp operator*(fp x, fp y) { FMT_FUNC fp get_cached_power(int min_exponent, int &pow10_exponent) { const double one_over_log2_10 = 0.30102999566398114; // 1 / log2(10) - int index = static_cast(std::ceil( - (min_exponent + fp::significand_size - 1) * one_over_log2_10)); + int index = static_cast( + std::ceil((min_exponent + fp::significand_size - 1) * one_over_log2_10)); // Decimal exponent of the first (smallest) cached power of 10. const int first_dec_exp = -348; // Difference between 2 consecutive decimal exponents in cached powers of 10. @@ -463,11 +451,12 @@ FMT_FUNC fp get_cached_power(int min_exponent, int &pow10_exponent) { return fp(data::POW10_SIGNIFICANDS[index], data::POW10_EXPONENTS[index]); } -FMT_FUNC bool grisu2_round( - char *buf, ptrdiff_t &size, size_t max_digits, uint64_t delta, - uint64_t remainder, uint64_t exp, uint64_t diff, int &exp10) { - while (remainder < diff && delta - remainder >= exp && - (remainder + exp < diff || diff - remainder > remainder + exp - diff)) { +FMT_FUNC bool grisu2_round(char *buf, ptrdiff_t &size, size_t max_digits, + uint64_t delta, uint64_t remainder, uint64_t exp, + uint64_t diff, int &exp10) { + while ( + remainder < diff && delta - remainder >= exp && + (remainder + exp < diff || diff - remainder > remainder + exp - diff)) { --buf[size - 1]; remainder += exp; } @@ -481,27 +470,58 @@ FMT_FUNC bool grisu2_round( } // Generates output using Grisu2 digit-gen algorithm. -FMT_FUNC bool grisu2_gen_digits( - char *buf, ptrdiff_t &size, uint32_t hi, uint64_t lo, int &exp, - uint64_t delta, const fp &one, const fp &diff, size_t max_digits) { +FMT_FUNC bool grisu2_gen_digits(char *buf, ptrdiff_t &size, uint32_t hi, + uint64_t lo, int &exp, uint64_t delta, + const fp &one, const fp &diff, + size_t max_digits) { // Generate digits for the most significant part (hi). while (exp > 0) { uint32_t digit = 0; // This optimization by miloyip reduces the number of integer divisions by // one per iteration. switch (exp) { - case 10: digit = hi / 1000000000; hi %= 1000000000; break; - case 9: digit = hi / 100000000; hi %= 100000000; break; - case 8: digit = hi / 10000000; hi %= 10000000; break; - case 7: digit = hi / 1000000; hi %= 1000000; break; - case 6: digit = hi / 100000; hi %= 100000; break; - case 5: digit = hi / 10000; hi %= 10000; break; - case 4: digit = hi / 1000; hi %= 1000; break; - case 3: digit = hi / 100; hi %= 100; break; - case 2: digit = hi / 10; hi %= 10; break; - case 1: digit = hi; hi = 0; break; - default: - FMT_ASSERT(false, "invalid number of digits"); + case 10: + digit = hi / 1000000000; + hi %= 1000000000; + break; + case 9: + digit = hi / 100000000; + hi %= 100000000; + break; + case 8: + digit = hi / 10000000; + hi %= 10000000; + break; + case 7: + digit = hi / 1000000; + hi %= 1000000; + break; + case 6: + digit = hi / 100000; + hi %= 100000; + break; + case 5: + digit = hi / 10000; + hi %= 10000; + break; + case 4: + digit = hi / 1000; + hi %= 1000; + break; + case 3: + digit = hi / 100; + hi %= 100; + break; + case 2: + digit = hi / 10; + hi %= 10; + break; + case 1: + digit = hi; + hi = 0; + break; + default: + FMT_ASSERT(false, "invalid number of digits"); } if (digit != 0 || size != 0) buf[size++] = static_cast('0' + digit); @@ -509,9 +529,9 @@ FMT_FUNC bool grisu2_gen_digits( uint64_t remainder = (static_cast(hi) << -one.e) + lo; if (remainder <= delta || size > static_cast(max_digits)) { return grisu2_round( - buf, size, max_digits, delta, remainder, - static_cast(data::POWERS_OF_10_32[exp]) << -one.e, - diff.f, exp); + buf, size, max_digits, delta, remainder, + static_cast(data::POWERS_OF_10_32[exp]) << -one.e, diff.f, + exp); } } // Generate digits for the least significant part (lo). @@ -531,11 +551,11 @@ FMT_FUNC bool grisu2_gen_digits( } #if FMT_CLANG_VERSION -# define FMT_FALLTHROUGH [[clang::fallthrough]]; +#define FMT_FALLTHROUGH [[clang::fallthrough]]; #elif FMT_GCC_VERSION >= 700 -# define FMT_FALLTHROUGH [[gnu::fallthrough]]; +#define FMT_FALLTHROUGH [[gnu::fallthrough]]; #else -# define FMT_FALLTHROUGH +#define FMT_FALLTHROUGH #endif struct gen_digits_params { @@ -551,7 +571,7 @@ struct prettify_handler { buffer &buf; explicit prettify_handler(buffer &b, ptrdiff_t n) - : data(b.data()), size(n), buf(b) {} + : data(b.data()), size(n), buf(b) {} ~prettify_handler() { assert(buf.size() >= to_unsigned(size)); buf.resize(to_unsigned(size)); @@ -616,8 +636,8 @@ struct fill { // The number is given as v = f * pow(10, exp), where f has size digits. template -FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms, - int size, int exp, Handler &&handler) { +FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms, int size, + int exp, Handler &&handler) { if (!params.fixed) { // Insert a decimal point after the first digit and add an exponent. handler.insert(1, '.'); @@ -660,7 +680,9 @@ struct char_counter { ptrdiff_t size; template - void insert(ptrdiff_t, ptrdiff_t n, F) { size += n; } + void insert(ptrdiff_t, ptrdiff_t n, F) { + size += n; + } void insert(ptrdiff_t, char) { ++size; } void append(ptrdiff_t n, char) { size += n; } void append(char) { ++size; } @@ -675,34 +697,35 @@ FMT_FUNC gen_digits_params process_specs(const core_format_specs &specs, auto params = gen_digits_params(); int num_digits = specs.precision >= 0 ? specs.precision : 6; switch (specs.type) { - case 'G': - params.upper = true; - FMT_FALLTHROUGH - case '\0': case 'g': - params.trailing_zeros = (specs.flags & HASH_FLAG) != 0; - if (-4 <= exp && exp < num_digits + 1) { + case 'G': + params.upper = true; + FMT_FALLTHROUGH + case '\0': + case 'g': + params.trailing_zeros = (specs.flags & HASH_FLAG) != 0; + if (-4 <= exp && exp < num_digits + 1) { + params.fixed = true; + if (!specs.type && params.trailing_zeros && exp >= 0) + num_digits = exp + 1; + } + break; + case 'F': + params.upper = true; + FMT_FALLTHROUGH + case 'f': { params.fixed = true; - if (!specs.type && params.trailing_zeros && exp >= 0) - num_digits = exp + 1; + params.trailing_zeros = true; + int adjusted_min_digits = num_digits + exp; + if (adjusted_min_digits > 0) + num_digits = adjusted_min_digits; + break; } - break; - case 'F': - params.upper = true; - FMT_FALLTHROUGH - case 'f': { - params.fixed = true; - params.trailing_zeros = true; - int adjusted_min_digits = num_digits + exp; - if (adjusted_min_digits > 0) - num_digits = adjusted_min_digits; - break; - } - case 'E': - params.upper = true; - FMT_FALLTHROUGH - case 'e': - ++num_digits; - break; + case 'E': + params.upper = true; + FMT_FALLTHROUGH + case 'e': + ++num_digits; + break; } params.num_digits = to_unsigned(num_digits); char_counter counter{num_digits}; @@ -713,7 +736,7 @@ FMT_FUNC gen_digits_params process_specs(const core_format_specs &specs, template FMT_FUNC typename std::enable_if::type - grisu2_format(Double value, buffer &buf, core_format_specs specs) { +grisu2_format(Double value, buffer &buf, core_format_specs specs) { FMT_ASSERT(value >= 0, "value is negative"); if (value == 0) { gen_digits_params params = process_specs(specs, 1, buf); @@ -728,13 +751,13 @@ FMT_FUNC typename std::enable_if::type fp_value.compute_boundaries(lower, upper); // Find a cached power of 10 close to 1 / upper and use it to scale upper. - const int min_exp = -60; // alpha in Grisu. - int cached_exp = 0; // K in Grisu. + const int min_exp = -60; // alpha in Grisu. + int cached_exp = 0; // K in Grisu. auto cached_pow = get_cached_power( // \tilde{c}_{-k} in Grisu. min_exp - (upper.e + fp::significand_size), cached_exp); cached_exp = -cached_exp; upper = upper * cached_pow; // \tilde{M}^+ in Grisu. - --upper.f; // \tilde{M}^+ - 1 ulp -> M^+_{\downarrow}. + --upper.f; // \tilde{M}^+ - 1 ulp -> M^+_{\downarrow}. fp one(1ull << -upper.e, upper.e); // hi (p1 in Grisu) contains the most significant digits of scaled_upper. // hi = floor(upper / one). @@ -744,9 +767,9 @@ FMT_FUNC typename std::enable_if::type fp_value.normalize(); fp scaled_value = fp_value * cached_pow; lower = lower * cached_pow; // \tilde{M}^- in Grisu. - ++lower.f; // \tilde{M}^- + 1 ulp -> M^-_{\uparrow}. + ++lower.f; // \tilde{M}^- + 1 ulp -> M^-_{\uparrow}. uint64_t delta = upper.f - lower.f; - fp diff = upper - scaled_value; // wp_w in Grisu. + fp diff = upper - scaled_value; // wp_w in Grisu. // lo (p2 in Grisu) contains the least significants digits of scaled_upper. // lo = supper % one. uint64_t lo = upper.f & (one.f - 1); @@ -767,7 +790,7 @@ void sprintf_format(Double value, internal::buffer &buf, FMT_ASSERT(buf.capacity() != 0, "empty buffer"); // Build format string. - enum { MAX_FORMAT_SIZE = 10}; // longest format: %#-*.*Lg + enum { MAX_FORMAT_SIZE = 10 }; // longest format: %#-*.*Lg char format[MAX_FORMAT_SIZE]; char *format_ptr = format; *format_ptr++ = '%'; @@ -819,13 +842,13 @@ FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) { return; } - int length = MultiByteToWideChar( - CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, FMT_NULL, 0); + int length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), + s_size, FMT_NULL, 0); if (length == 0) FMT_THROW(windows_error(GetLastError(), ERROR_MSG)); buffer_.resize(length + 1); - length = MultiByteToWideChar( - CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, &buffer_[0], length); + length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, + &buffer_[0], length); if (length == 0) FMT_THROW(windows_error(GetLastError(), ERROR_MSG)); buffer_[length] = 0; @@ -834,7 +857,7 @@ FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) { FMT_FUNC internal::utf16_to_utf8::utf16_to_utf8(wstring_view s) { if (int error_code = convert(s)) { FMT_THROW(windows_error(error_code, - "cannot convert string from UTF-16 to UTF-8")); + "cannot convert string from UTF-16 to UTF-8")); } } @@ -849,21 +872,21 @@ FMT_FUNC int internal::utf16_to_utf8::convert(wstring_view s) { return 0; } - int length = WideCharToMultiByte( - CP_UTF8, 0, s.data(), s_size, FMT_NULL, 0, FMT_NULL, FMT_NULL); + int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, FMT_NULL, 0, + FMT_NULL, FMT_NULL); if (length == 0) return GetLastError(); buffer_.resize(length + 1); - length = WideCharToMultiByte( - CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, FMT_NULL, FMT_NULL); + length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, &buffer_[0], + length, FMT_NULL, FMT_NULL); if (length == 0) return GetLastError(); buffer_[length] = 0; return 0; } -FMT_FUNC void windows_error::init( - int err_code, string_view format_str, format_args args) { +FMT_FUNC void windows_error::init(int err_code, string_view format_str, + format_args args) { error_code_ = err_code; memory_buffer buffer; internal::format_windows_error(buffer, err_code, vformat(format_str, args)); @@ -871,17 +894,18 @@ FMT_FUNC void windows_error::init( base = std::runtime_error(to_string(buffer)); } -FMT_FUNC void internal::format_windows_error( - internal::buffer &out, int error_code, string_view message) FMT_NOEXCEPT { +FMT_FUNC void internal::format_windows_error(internal::buffer &out, + int error_code, + string_view message) FMT_NOEXCEPT { FMT_TRY { wmemory_buffer buf; buf.resize(inline_buffer_size); for (;;) { wchar_t *system_message = &buf[0]; int result = FormatMessageW( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - FMT_NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - system_message, static_cast(buf.size()), FMT_NULL); + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FMT_NULL, + error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), system_message, + static_cast(buf.size()), FMT_NULL); if (result != 0) { utf16_to_utf8 utf8_message; if (utf8_message.convert(system_message) == ERROR_SUCCESS) { @@ -897,14 +921,15 @@ FMT_FUNC void internal::format_windows_error( break; // Can't get error message, report error code instead. buf.resize(buf.size() * 2); } - } FMT_CATCH(...) {} + } + FMT_CATCH(...) {} format_error_code(out, error_code, message); } #endif // FMT_USE_WINDOWS_H -FMT_FUNC void format_system_error( - internal::buffer &out, int error_code, string_view message) FMT_NOEXCEPT { +FMT_FUNC void format_system_error(internal::buffer &out, int error_code, + string_view message) FMT_NOEXCEPT { FMT_TRY { memory_buffer buf; buf.resize(inline_buffer_size); @@ -922,7 +947,8 @@ FMT_FUNC void format_system_error( break; // Can't get error message, report error code instead. buf.resize(buf.size() * 2); } - } FMT_CATCH(...) {} + } + FMT_CATCH(...) {} format_error_code(out, error_code, message); } @@ -930,14 +956,14 @@ FMT_FUNC void internal::error_handler::on_error(const char *message) { FMT_THROW(format_error(message)); } -FMT_FUNC void report_system_error( - int error_code, fmt::string_view message) FMT_NOEXCEPT { +FMT_FUNC void report_system_error(int error_code, + fmt::string_view message) FMT_NOEXCEPT { report_error(format_system_error, error_code, message); } #if FMT_USE_WINDOWS_H -FMT_FUNC void report_windows_error( - int error_code, fmt::string_view message) FMT_NOEXCEPT { +FMT_FUNC void report_windows_error(int error_code, + fmt::string_view message) FMT_NOEXCEPT { report_error(internal::format_windows_error, error_code, message); } #endif @@ -966,7 +992,7 @@ FMT_FUNC void vprint(wstring_view format_str, wformat_args args) { FMT_END_NAMESPACE #ifdef _MSC_VER -# pragma warning(pop) +#pragma warning(pop) #endif #endif // FMT_FORMAT_INL_H_ diff --git a/include/fmt/format.h b/include/fmt/format.h index a4d79090..ba60fdb5 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -31,77 +31,77 @@ #include #include #include +#include #include #include #include #include -#include #ifdef __clang__ -# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) +#define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) #else -# define FMT_CLANG_VERSION 0 +#define FMT_CLANG_VERSION 0 #endif #ifdef __INTEL_COMPILER -# define FMT_ICC_VERSION __INTEL_COMPILER +#define FMT_ICC_VERSION __INTEL_COMPILER #elif defined(__ICL) -# define FMT_ICC_VERSION __ICL +#define FMT_ICC_VERSION __ICL #else -# define FMT_ICC_VERSION 0 +#define FMT_ICC_VERSION 0 #endif #ifdef __NVCC__ -# define FMT_CUDA_VERSION (__CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__) +#define FMT_CUDA_VERSION (__CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__) #else -# define FMT_CUDA_VERSION 0 +#define FMT_CUDA_VERSION 0 #endif #include "core.h" #if FMT_GCC_VERSION >= 406 || FMT_CLANG_VERSION -# pragma GCC diagnostic push +#pragma GCC diagnostic push // Disable the warning about declaration shadowing because it affects too // many valid cases. -# pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wshadow" // Disable the warning about implicit conversions that may change the sign of // an integer; silencing it otherwise would require many explicit casts. -# pragma GCC diagnostic ignored "-Wsign-conversion" +#pragma GCC diagnostic ignored "-Wsign-conversion" // Disable the warning about nonliteral format strings because we construct // them dynamically when falling back to snprintf for FP formatting. -# pragma GCC diagnostic ignored "-Wformat-nonliteral" +#pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif -# if FMT_CLANG_VERSION -# pragma GCC diagnostic ignored "-Wgnu-string-literal-operator-template" -# endif +#if FMT_CLANG_VERSION +#pragma GCC diagnostic ignored "-Wgnu-string-literal-operator-template" +#endif #ifdef _SECURE_SCL -# define FMT_SECURE_SCL _SECURE_SCL +#define FMT_SECURE_SCL _SECURE_SCL #else -# define FMT_SECURE_SCL 0 +#define FMT_SECURE_SCL 0 #endif #if FMT_SECURE_SCL -# include +#include #endif #ifdef __has_builtin -# define FMT_HAS_BUILTIN(x) __has_builtin(x) +#define FMT_HAS_BUILTIN(x) __has_builtin(x) #else -# define FMT_HAS_BUILTIN(x) 0 +#define FMT_HAS_BUILTIN(x) 0 #endif #ifdef __GNUC_LIBSTD__ -# define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__) +#define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__) #endif #ifndef FMT_THROW -# if FMT_EXCEPTIONS -# if FMT_MSC_VER +#if FMT_EXCEPTIONS +#if FMT_MSC_VER FMT_BEGIN_NAMESPACE namespace internal { template @@ -112,88 +112,91 @@ inline void do_throw(const Exception &x) { if (b) throw x; } -} +} // namespace internal FMT_END_NAMESPACE -# define FMT_THROW(x) fmt::internal::do_throw(x) -# else -# define FMT_THROW(x) throw x -# endif -# else -# define FMT_THROW(x) do { static_cast(sizeof(x)); assert(false); } while(false); -# endif +#define FMT_THROW(x) fmt::internal::do_throw(x) +#else +#define FMT_THROW(x) throw x +#endif +#else +#define FMT_THROW(x) \ + do { \ + static_cast(sizeof(x)); \ + assert(false); \ + } while (false); +#endif #endif #ifndef FMT_USE_USER_DEFINED_LITERALS // For Intel's compiler and NVIDIA's compiler both it and the system gcc/msc // must support UDLs. -# if (FMT_HAS_FEATURE(cxx_user_literals) || \ - FMT_GCC_VERSION >= 407 || FMT_MSC_VER >= 1900) && \ - (!(FMT_ICC_VERSION || FMT_CUDA_VERSION) || \ - FMT_ICC_VERSION >= 1500 || FMT_CUDA_VERSION >= 700) -# define FMT_USE_USER_DEFINED_LITERALS 1 -# else -# define FMT_USE_USER_DEFINED_LITERALS 0 -# endif +#if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION >= 407 || \ + FMT_MSC_VER >= 1900) && \ + (!(FMT_ICC_VERSION || FMT_CUDA_VERSION) || FMT_ICC_VERSION >= 1500 || \ + FMT_CUDA_VERSION >= 700) +#define FMT_USE_USER_DEFINED_LITERALS 1 +#else +#define FMT_USE_USER_DEFINED_LITERALS 0 +#endif #endif // EDG C++ Front End based compilers (icc, nvcc) do not currently support UDL // templates. -#if FMT_USE_USER_DEFINED_LITERALS && \ - FMT_ICC_VERSION == 0 && \ - FMT_CUDA_VERSION == 0 && \ - ((FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L) || \ - (defined(FMT_CLANG_VERSION) && FMT_CLANG_VERSION >= 304)) -# define FMT_UDL_TEMPLATE 1 +#if FMT_USE_USER_DEFINED_LITERALS && FMT_ICC_VERSION == 0 && \ + FMT_CUDA_VERSION == 0 && \ + ((FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L) || \ + (defined(FMT_CLANG_VERSION) && FMT_CLANG_VERSION >= 304)) +#define FMT_UDL_TEMPLATE 1 #else -# define FMT_UDL_TEMPLATE 0 +#define FMT_UDL_TEMPLATE 0 #endif #ifndef FMT_USE_EXTERN_TEMPLATES -# ifndef FMT_HEADER_ONLY -# define FMT_USE_EXTERN_TEMPLATES \ - ((FMT_CLANG_VERSION >= 209 && __cplusplus >= 201103L) || \ - (FMT_GCC_VERSION >= 303 && FMT_HAS_GXX_CXX11)) -# else -# define FMT_USE_EXTERN_TEMPLATES 0 -# endif +#ifndef FMT_HEADER_ONLY +#define FMT_USE_EXTERN_TEMPLATES \ + ((FMT_CLANG_VERSION >= 209 && __cplusplus >= 201103L) || \ + (FMT_GCC_VERSION >= 303 && FMT_HAS_GXX_CXX11)) +#else +#define FMT_USE_EXTERN_TEMPLATES 0 +#endif #endif #if FMT_HAS_GXX_CXX11 || FMT_HAS_FEATURE(cxx_trailing_return) || \ FMT_MSC_VER >= 1600 -# define FMT_USE_TRAILING_RETURN 1 +#define FMT_USE_TRAILING_RETURN 1 #else -# define FMT_USE_TRAILING_RETURN 0 +#define FMT_USE_TRAILING_RETURN 0 #endif #ifndef FMT_USE_GRISU -# define FMT_USE_GRISU 0 +#define FMT_USE_GRISU 0 //# define FMT_USE_GRISU std::numeric_limits::is_iec559 #endif // __builtin_clz is broken in clang with Microsoft CodeGen: // https://github.com/fmtlib/fmt/issues/519 #ifndef _MSC_VER -# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) -# define FMT_BUILTIN_CLZ(n) __builtin_clz(n) -# endif +#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) +#define FMT_BUILTIN_CLZ(n) __builtin_clz(n) +#endif -# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll) -# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) -# endif +#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll) +#define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) +#endif #endif // Some compilers masquerade as both MSVC and GCC-likes or otherwise support // __builtin_clz and __builtin_clzll, so only define FMT_BUILTIN_CLZ using the // MSVC intrinsics if the clz and clzll builtins are not available. #if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL) && !defined(_MANAGED) -# include // _BitScanReverse, _BitScanReverse64 +#include // _BitScanReverse, _BitScanReverse64 FMT_BEGIN_NAMESPACE namespace internal { // Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning. -# ifndef __clang__ -# pragma intrinsic(_BitScanReverse) -# endif +#ifndef __clang__ +#pragma intrinsic(_BitScanReverse) +#endif inline uint32_t clz(uint32_t x) { unsigned long r = 0; _BitScanReverse(&r, x); @@ -202,37 +205,37 @@ inline uint32_t clz(uint32_t x) { // Static analysis complains about using uninitialized data // "r", but the only way that can happen is if "x" is 0, // which the callers guarantee to not happen. -# pragma warning(suppress: 6102) +#pragma warning(suppress : 6102) return 31 - r; } -# define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n) +#define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n) -# if defined(_WIN64) && !defined(__clang__) -# pragma intrinsic(_BitScanReverse64) -# endif +#if defined(_WIN64) && !defined(__clang__) +#pragma intrinsic(_BitScanReverse64) +#endif inline uint32_t clzll(uint64_t x) { unsigned long r = 0; -# ifdef _WIN64 +#ifdef _WIN64 _BitScanReverse64(&r, x); -# else +#else // Scan the high 32 bits. if (_BitScanReverse(&r, static_cast(x >> 32))) return 63 - (r + 32); // Scan the low 32 bits. _BitScanReverse(&r, static_cast(x)); -# endif +#endif assert(x != 0); // Static analysis complains about using uninitialized data // "r", but the only way that can happen is if "x" is 0, // which the callers guarantee to not happen. -# pragma warning(suppress: 6102) +#pragma warning(suppress : 6102) return 63 - r; } -# define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n) -} +#define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n) +} // namespace internal FMT_END_NAMESPACE #endif @@ -243,7 +246,7 @@ namespace internal { // undefined behavior (e.g. due to type aliasing). // Example: uint64_t d = bit_cast(2.718); template -inline Dest bit_cast(const Source& source) { +inline Dest bit_cast(const Source &source) { static_assert(sizeof(Dest) == sizeof(Source), "size mismatch"); Dest dest; std::memcpy(&dest, &source, sizeof(dest)); @@ -256,17 +259,25 @@ FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin()) { return c.begin(); } template -FMT_CONSTEXPR T *begin(T (&array)[N]) FMT_NOEXCEPT { return array; } +FMT_CONSTEXPR T *begin(T (&array)[N]) FMT_NOEXCEPT { + return array; +} template -FMT_CONSTEXPR auto end(const C &c) -> decltype(c.end()) { return c.end(); } +FMT_CONSTEXPR auto end(const C &c) -> decltype(c.end()) { + return c.end(); +} template -FMT_CONSTEXPR T *end(T (&array)[N]) FMT_NOEXCEPT { return array + N; } +FMT_CONSTEXPR T *end(T (&array)[N]) FMT_NOEXCEPT { + return array + N; +} // For std::result_of in gcc 4.4. template struct function { template - struct result { typedef Result type; }; + struct result { + typedef Result type; + }; }; struct dummy_int { @@ -283,7 +294,7 @@ inline dummy_int isnan(...) { return dummy_int(); } inline dummy_int _isnan(...) { return dummy_int(); } template -typename Allocator::value_type *allocate(Allocator& alloc, std::size_t n) { +typename Allocator::value_type *allocate(Allocator &alloc, std::size_t n) { #if __cplusplus >= 201103L || FMT_MSC_VER >= 1700 return std::allocator_traits::allocate(alloc, n); #else @@ -294,7 +305,9 @@ typename Allocator::value_type *allocate(Allocator& alloc, std::size_t n) { // A helper function to suppress bogus "conditional expression is constant" // warnings. template -inline T const_check(T value) { return value; } +inline T const_check(T value) { + return value; +} } // namespace internal FMT_END_NAMESPACE @@ -304,8 +317,8 @@ namespace std { // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891 // and the same for isnan. template <> -class numeric_limits : - public std::numeric_limits { +class numeric_limits + : public std::numeric_limits { public: // Portable version of isinf. template @@ -346,20 +359,21 @@ class output_range { typedef OutputIt iterator; typedef T value_type; - explicit output_range(OutputIt it): it_(it) {} + explicit output_range(OutputIt it) : it_(it) {} OutputIt begin() const { return it_; } }; // A range where begin() returns back_insert_iterator. template -class back_insert_range: - public output_range> { +class back_insert_range + : public output_range> { typedef output_range> base; + public: typedef typename Container::value_type value_type; - back_insert_range(Container &c): base(std::back_inserter(c)) {} - back_insert_range(typename base::iterator it): base(it) {} + back_insert_range(Container &c) : base(std::back_inserter(c)) {} + back_insert_range(typename base::iterator it) : base(it) {} }; typedef basic_writer> writer; @@ -368,29 +382,35 @@ typedef basic_writer> wwriter; /** A formatting error such as invalid format string. */ class format_error : public std::runtime_error { public: - explicit format_error(const char *message) - : std::runtime_error(message) {} + explicit format_error(const char *message) : std::runtime_error(message) {} explicit format_error(const std::string &message) - : std::runtime_error(message) {} + : std::runtime_error(message) {} }; namespace internal { #if FMT_SECURE_SCL template -struct checked { typedef stdext::checked_array_iterator type; }; +struct checked { + typedef stdext::checked_array_iterator type; +}; // Make a checked iterator to avoid warnings on MSVC. template -inline stdext::checked_array_iterator make_checked(T *p, std::size_t size) { +inline stdext::checked_array_iterator make_checked(T *p, + std::size_t size) { return {p, size}; } #else template -struct checked { typedef T *type; }; +struct checked { + typedef T *type; +}; template -inline T *make_checked(T *p, std::size_t) { return p; } +inline T *make_checked(T *p, std::size_t) { + return p; +} #endif template @@ -408,7 +428,7 @@ void basic_buffer::append(const U *begin, const U *end) { // type in this mode. If this is the case __cpp_char8_t will be defined. #if !defined(__cpp_char8_t) // A UTF-8 code unit type. -enum char8_t: unsigned char {}; +enum char8_t : unsigned char {}; #endif // A UTF-8 string view. @@ -416,10 +436,11 @@ class u8string_view : public basic_string_view { public: typedef char8_t char_type; - u8string_view(const char *s): - basic_string_view(reinterpret_cast(s)) {} - u8string_view(const char *s, size_t count) FMT_NOEXCEPT: - basic_string_view(reinterpret_cast(s), count) {} + u8string_view(const char *s) + : basic_string_view(reinterpret_cast(s)) {} + u8string_view(const char *s, size_t count) FMT_NOEXCEPT + : basic_string_view(reinterpret_cast(s), + count) {} }; #if FMT_USE_USER_DEFINED_LITERALS @@ -427,7 +448,7 @@ inline namespace literals { inline u8string_view operator"" _u(const char *s, std::size_t n) { return {s, n}; } -} +} // namespace literals #endif // The number of characters to store in the basic_memory_buffer object itself @@ -464,15 +485,17 @@ enum { inline_buffer_size = 500 }; \endrst */ template > -class basic_memory_buffer: private Allocator, public internal::basic_buffer { + typename Allocator = std::allocator> +class basic_memory_buffer : private Allocator, + public internal::basic_buffer { private: T store_[SIZE]; // Deallocate memory allocated by the buffer. void deallocate() { - T* data = this->data(); - if (data != store_) Allocator::deallocate(data, this->capacity()); + T *data = this->data(); + if (data != store_) + Allocator::deallocate(data, this->capacity()); } protected: @@ -490,7 +513,7 @@ class basic_memory_buffer: private Allocator, public internal::basic_buffer { void move(basic_memory_buffer &other) { Allocator &this_alloc = *this, &other_alloc = other; this_alloc = std::move(other_alloc); - T* data = other.data(); + T *data = other.data(); std::size_t size = other.size(), capacity = other.capacity(); if (data == other.store_) { this->set(store_, capacity); @@ -512,9 +535,7 @@ class basic_memory_buffer: private Allocator, public internal::basic_buffer { of the other object to it. \endrst */ - basic_memory_buffer(basic_memory_buffer &&other) { - move(other); - } + basic_memory_buffer(basic_memory_buffer &&other) { move(other); } /** \rst @@ -537,7 +558,7 @@ void basic_memory_buffer::grow(std::size_t size) { std::size_t old_capacity = this->capacity(); std::size_t new_capacity = old_capacity + old_capacity / 2; if (size > new_capacity) - new_capacity = size; + new_capacity = size; T *old_data = this->data(); T *new_data = internal::allocate(*this, new_capacity); // The following code doesn't throw, so the raw pointer above doesn't leak. @@ -564,37 +585,40 @@ struct char_traits { // Formats a floating-point number. template FMT_API static int format_float(char *buffer, std::size_t size, - const char *format, int precision, T value); + const char *format, int precision, T value); }; template <> struct char_traits { template FMT_API static int format_float(wchar_t *buffer, std::size_t size, - const wchar_t *format, int precision, T value); + const wchar_t *format, int precision, + T value); }; #if FMT_USE_EXTERN_TEMPLATES -extern template int char_traits::format_float( - char *buffer, std::size_t size, const char* format, int precision, - double value); +extern template int char_traits::format_float(char *buffer, + std::size_t size, + const char *format, + int precision, + double value); extern template int char_traits::format_float( - char *buffer, std::size_t size, const char* format, int precision, + char *buffer, std::size_t size, const char *format, int precision, long double value); extern template int char_traits::format_float( - wchar_t *buffer, std::size_t size, const wchar_t* format, int precision, + wchar_t *buffer, std::size_t size, const wchar_t *format, int precision, double value); extern template int char_traits::format_float( - wchar_t *buffer, std::size_t size, const wchar_t* format, int precision, + wchar_t *buffer, std::size_t size, const wchar_t *format, int precision, long double value); #endif template inline typename std::enable_if< - is_contiguous::value, - typename checked::type>::type - reserve(std::back_insert_iterator &it, std::size_t n) { + is_contiguous::value, + typename checked::type>::type +reserve(std::back_insert_iterator &it, std::size_t n) { Container &c = internal::get_container(it); std::size_t size = c.size(); c.resize(size + n); @@ -602,7 +626,9 @@ inline typename std::enable_if< } template -inline Iterator &reserve(Iterator &it, std::size_t) { return it; } +inline Iterator &reserve(Iterator &it, std::size_t) { + return it; +} template class null_terminating_iterator; @@ -622,15 +648,15 @@ class counting_iterator { typedef std::output_iterator_tag iterator_category; typedef T value_type; typedef std::ptrdiff_t difference_type; - typedef T* pointer; - typedef T& reference; + typedef T *pointer; + typedef T &reference; typedef counting_iterator _Unchecked_type; // Mark iterator as checked. - counting_iterator(): count_(0) {} + counting_iterator() : count_(0) {} std::size_t count() const { return count_; } - counting_iterator& operator++() { + counting_iterator &operator++() { ++count_; return *this; } @@ -652,14 +678,15 @@ class truncating_iterator_base { std::size_t count_; truncating_iterator_base(OutputIt out, std::size_t limit) - : out_(out), limit_(limit), count_(0) {} + : out_(out), limit_(limit), count_(0) {} public: typedef std::output_iterator_tag iterator_category; typedef void difference_type; typedef void pointer; typedef void reference; - typedef truncating_iterator_base _Unchecked_type; // Mark iterator as checked. + typedef truncating_iterator_base + _Unchecked_type; // Mark iterator as checked. OutputIt base() const { return out_; } std::size_t count() const { return count_; } @@ -667,13 +694,14 @@ class truncating_iterator_base { // An output iterator that truncates the output and counts the number of objects // written to it. -template ::value_type>::type> +template ::value_type>::type> class truncating_iterator; template -class truncating_iterator: - public truncating_iterator_base { +class truncating_iterator + : public truncating_iterator_base { typedef std::iterator_traits traits; mutable typename traits::value_type blackhole_; @@ -682,9 +710,9 @@ class truncating_iterator: typedef typename traits::value_type value_type; truncating_iterator(OutputIt out, std::size_t limit) - : truncating_iterator_base(out, limit) {} + : truncating_iterator_base(out, limit) {} - truncating_iterator& operator++() { + truncating_iterator &operator++() { if (this->count_++ < this->limit_) ++this->out_; return *this; @@ -696,41 +724,43 @@ class truncating_iterator: return it; } - value_type& operator*() const { + value_type &operator*() const { return this->count_ < this->limit_ ? *this->out_ : blackhole_; } }; template -class truncating_iterator: - public truncating_iterator_base { +class truncating_iterator + : public truncating_iterator_base { public: typedef typename OutputIt::container_type::value_type value_type; truncating_iterator(OutputIt out, std::size_t limit) - : truncating_iterator_base(out, limit) {} + : truncating_iterator_base(out, limit) {} - truncating_iterator& operator=(value_type val) { + truncating_iterator &operator=(value_type val) { if (this->count_++ < this->limit_) this->out_ = val; return *this; } - truncating_iterator& operator++() { return *this; } - truncating_iterator& operator++(int) { return *this; } - truncating_iterator& operator*() { return *this; } + truncating_iterator &operator++() { return *this; } + truncating_iterator &operator++(int) { return *this; } + truncating_iterator &operator*() { return *this; } }; // Returns true if value is negative, false otherwise. // Same as (value < 0) but doesn't produce warnings if T is an unsigned type. template -FMT_CONSTEXPR typename std::enable_if< - std::numeric_limits::is_signed, bool>::type is_negative(T value) { +FMT_CONSTEXPR + typename std::enable_if::is_signed, bool>::type + is_negative(T value) { return value < 0; } template -FMT_CONSTEXPR typename std::enable_if< - !std::numeric_limits::is_signed, bool>::type is_negative(T) { +FMT_CONSTEXPR + typename std::enable_if::is_signed, bool>::type + is_negative(T) { return false; } @@ -738,8 +768,8 @@ template struct int_traits { // Smallest of uint32_t and uint64_t that is large enough to represent // all values of T. - typedef typename std::conditional< - std::numeric_limits::digits <= 32, uint32_t, uint64_t>::type main_type; + typedef typename std::conditional::digits <= 32, + uint32_t, uint64_t>::type main_type; }; // Static data is placed in this class template to allow header-only @@ -781,10 +811,14 @@ inline unsigned count_digits(uint64_t n) { // Integer division is slow so do it for a group of four digits instead // of for every digit. The idea comes from the talk by Alexandrescu // "Three Optimization Tips for C++". See speed-test for a comparison. - if (n < 10) return count; - if (n < 100) return count + 1; - if (n < 1000) return count + 2; - if (n < 10000) return count + 3; + if (n < 10) + return count; + if (n < 100) + return count + 1; + if (n < 1000) + return count + 2; + if (n < 10000) + return count + 3; n /= 10000u; count += 4; } @@ -792,7 +826,9 @@ inline unsigned count_digits(uint64_t n) { #endif template -inline size_t count_code_points(basic_string_view s) { return s.size(); } +inline size_t count_code_points(basic_string_view s) { + return s.size(); +} // Counts the number of code points in a UTF-8 string. FMT_API size_t count_code_points(basic_string_view s); @@ -800,29 +836,30 @@ FMT_API size_t count_code_points(basic_string_view s); inline char8_t to_char8_t(char c) { return static_cast(c); } template -struct needs_conversion: std::integral_constant::value_type, char>::value && - std::is_same::value> {}; +struct needs_conversion + : std::integral_constant< + bool, std::is_same::value_type, + char>::value && + std::is_same::value> {}; template -typename std::enable_if< - !needs_conversion::value, OutputIt>::type - copy_str(InputIt begin, InputIt end, OutputIt it) { +typename std::enable_if::value, + OutputIt>::type +copy_str(InputIt begin, InputIt end, OutputIt it) { return std::copy(begin, end, it); } template -typename std::enable_if< - needs_conversion::value, OutputIt>::type - copy_str(InputIt begin, InputIt end, OutputIt it) { +typename std::enable_if::value, + OutputIt>::type +copy_str(InputIt begin, InputIt end, OutputIt it) { return std::transform(begin, end, it, to_char8_t); } #if FMT_HAS_CPP_ATTRIBUTE(always_inline) -# define FMT_ALWAYS_INLINE __attribute__((always_inline)) +#define FMT_ALWAYS_INLINE __attribute__((always_inline)) #else -# define FMT_ALWAYS_INLINE +#define FMT_ALWAYS_INLINE #endif template @@ -856,7 +893,8 @@ class decimal_formatter { public: explicit decimal_formatter(char *buf) : buffer_(buf) {} - template char *on(uint32_t u) { + template + char *on(uint32_t u) { if (N == 0) { *buffer_ = static_cast(u) + '0'; } else if (N == 1) { @@ -866,8 +904,8 @@ class decimal_formatter { // https://github.com/jeaiii/itoa unsigned n = N - 1; unsigned a = n / 5 * n * 53 / 16; - uint64_t t = ((1ULL << (32 + a)) / - data::ZERO_OR_POWERS_OF_10_32[n] + 1 - n / 9); + uint64_t t = + ((1ULL << (32 + a)) / data::ZERO_OR_POWERS_OF_10_32[n] + 1 - n / 9); t = ((t * u) >> a) + n / 5 * 4; write_pair(0, t >> 32); for (unsigned i = 2; i < N; i += 2) { @@ -875,8 +913,8 @@ class decimal_formatter { write_pair(i, t >> 32); } if (N % 2 == 0) { - buffer_[N] = static_cast( - (10ULL * static_cast(t)) >> 32) + '0'; + buffer_[N] = + static_cast((10ULL * static_cast(t)) >> 32) + '0'; } } return buffer_ += N + 1; @@ -888,7 +926,8 @@ class decimal_formatter_null : public decimal_formatter { public: explicit decimal_formatter_null(char *buf) : decimal_formatter(buf) {} - template char *on(uint32_t u) { + template + char *on(uint32_t u) { char *buf = decimal_formatter::on(u); *buf = '\0'; return buf; @@ -926,7 +965,7 @@ class add_thousands_sep { typedef Char char_type; explicit add_thousands_sep(basic_string_view sep) - : sep_(sep), digit_index_(0) {} + : sep_(sep), digit_index_(0) {} void operator()(Char *&buffer) { if (++digit_index_ % 3 != 0) @@ -984,8 +1023,8 @@ inline Char *format_decimal(Char *buffer, UInt value, unsigned num_digits, template -inline Iterator format_decimal( - Iterator out, UInt value, unsigned num_digits, ThousandsSep sep) { +inline Iterator format_decimal(Iterator out, UInt value, unsigned num_digits, + ThousandsSep sep) { typedef typename ThousandsSep::char_type char_type; // Buffer should be large enough to hold all digits (<= digits10 + 1). enum { max_size = std::numeric_limits::digits10 + 1 }; @@ -1024,9 +1063,9 @@ inline It format_uint(It out, UInt value, unsigned num_digits, } #ifndef _WIN32 -# define FMT_USE_WINDOWS_H 0 +#define FMT_USE_WINDOWS_H 0 #elif !defined(FMT_USE_WINDOWS_H) -# define FMT_USE_WINDOWS_H 1 +#define FMT_USE_WINDOWS_H 1 #endif // Define FMT_USE_WINDOWS_H to 0 to disable use of windows.h. @@ -1075,7 +1114,11 @@ struct null {}; } // namespace internal enum alignment { - ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC + ALIGN_DEFAULT, + ALIGN_LEFT, + ALIGN_RIGHT, + ALIGN_CENTER, + ALIGN_NUMERIC }; // Flags. @@ -1126,10 +1169,12 @@ namespace internal { // https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf template FMT_API typename std::enable_if::type - grisu2_format(Double value, buffer &buf, core_format_specs); +grisu2_format(Double value, buffer &buf, core_format_specs); template inline typename std::enable_if::type - grisu2_format(Double, buffer &, core_format_specs) { return false; } +grisu2_format(Double, buffer &, core_format_specs) { + return false; +} template void sprintf_format(Double, internal::buffer &, core_format_specs); @@ -1137,52 +1182,62 @@ void sprintf_format(Double, internal::buffer &, core_format_specs); template FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler &&handler) { switch (spec) { - case 0: case 'd': - handler.on_dec(); - break; - case 'x': case 'X': - handler.on_hex(); - break; - case 'b': case 'B': - handler.on_bin(); - break; - case 'o': - handler.on_oct(); - break; - case 'n': - handler.on_num(); - break; - default: - handler.on_error(); + case 0: + case 'd': + handler.on_dec(); + break; + case 'x': + case 'X': + handler.on_hex(); + break; + case 'b': + case 'B': + handler.on_bin(); + break; + case 'o': + handler.on_oct(); + break; + case 'n': + handler.on_num(); + break; + default: + handler.on_error(); } } template FMT_CONSTEXPR void handle_float_type_spec(char spec, Handler &&handler) { switch (spec) { - case 0: case 'g': case 'G': - handler.on_general(); - break; - case 'e': case 'E': - handler.on_exp(); - break; - case 'f': case 'F': - handler.on_fixed(); - break; - case 'a': case 'A': - handler.on_hex(); - break; - default: - handler.on_error(); - break; + case 0: + case 'g': + case 'G': + handler.on_general(); + break; + case 'e': + case 'E': + handler.on_exp(); + break; + case 'f': + case 'F': + handler.on_fixed(); + break; + case 'a': + case 'A': + handler.on_hex(); + break; + default: + handler.on_error(); + break; } } template -FMT_CONSTEXPR void handle_char_specs( - const basic_format_specs *specs, Handler &&handler) { - if (!specs) return handler.on_char(); - if (specs->type && specs->type != 'c') return handler.on_int(); +FMT_CONSTEXPR void handle_char_specs(const basic_format_specs *specs, + Handler &&handler) { + if (!specs) + return handler.on_char(); + if (specs->type && specs->type != 'c') + return handler.on_int(); if (specs->align() == ALIGN_NUMERIC || specs->flags != 0) handler.on_error("invalid format specifier for char"); handler.on_char(); @@ -1230,7 +1285,7 @@ template class float_type_checker : private ErrorHandler { public: FMT_CONSTEXPR explicit float_type_checker(ErrorHandler eh) - : ErrorHandler(eh) {} + : ErrorHandler(eh) {} FMT_CONSTEXPR void on_general() {} FMT_CONSTEXPR void on_exp() {} @@ -1249,7 +1304,7 @@ class char_specs_checker : public ErrorHandler { public: FMT_CONSTEXPR char_specs_checker(char type, ErrorHandler eh) - : ErrorHandler(eh), type_(type) {} + : ErrorHandler(eh), type_(type) {} FMT_CONSTEXPR void on_int() { handle_int_type_spec(type_, int_type_checker(*this)); @@ -1261,7 +1316,7 @@ template class cstring_type_checker : public ErrorHandler { public: FMT_CONSTEXPR explicit cstring_type_checker(ErrorHandler eh) - : ErrorHandler(eh) {} + : ErrorHandler(eh) {} FMT_CONSTEXPR void on_string() {} FMT_CONSTEXPR void on_pointer() {} @@ -1273,7 +1328,7 @@ void arg_map::init(const basic_format_args &args) { return; map_ = new entry[args.max_size()]; if (args.is_packed()) { - for (unsigned i = 0;/*nothing*/; ++i) { + for (unsigned i = 0; /*nothing*/; ++i) { internal::type arg_type = args.type(i); switch (arg_type) { case internal::none_type: @@ -1282,11 +1337,11 @@ void arg_map::init(const basic_format_args &args) { push_back(args.values_[i]); break; default: - break; // Do nothing. + break; // Do nothing. } } } - for (unsigned i = 0; ; ++i) { + for (unsigned i = 0;; ++i) { switch (args.args_[i].type_) { case internal::none_type: return; @@ -1294,7 +1349,7 @@ void arg_map::init(const basic_format_args &args) { push_back(args.args_[i].value_); break; default: - break; // Do nothing. + break; // Do nothing. } } } @@ -1318,7 +1373,9 @@ class arg_formatter_base { size_t width() const { return 1; } template - void operator()(It &&it) const { *it++ = value; } + void operator()(It &&it) const { + *it++ = value; + } }; void write_char(char_type value) { @@ -1355,7 +1412,7 @@ class arg_formatter_base { public: arg_formatter_base(Range r, format_specs *s, locale_ref loc) - : writer_(r, loc), specs_(s) {} + : writer_(r, loc), specs_(s) {} iterator operator()(monostate) { FMT_ASSERT(false, "invalid argument type"); @@ -1363,9 +1420,10 @@ class arg_formatter_base { } template - typename std::enable_if< - std::is_integral::value || std::is_same::value, - iterator>::type operator()(T value) { + typename std::enable_if::value || + std::is_same::value, + iterator>::type + operator()(T value) { // MSVC2013 fails to compile separate overloads for bool and char_type so // use std::is_same instead. if (std::is_same::value) { @@ -1374,7 +1432,7 @@ class arg_formatter_base { write(value != 0); } else if (std::is_same::value) { internal::handle_char_specs( - specs_, char_spec_handler(*this, static_cast(value))); + specs_, char_spec_handler(*this, static_cast(value))); } else { specs_ ? writer_.write_int(value, *specs_) : writer_.write(value); } @@ -1383,7 +1441,7 @@ class arg_formatter_base { template typename std::enable_if::value, iterator>::type - operator()(T value) { + operator()(T value) { writer_.write_double(value, specs_ ? *specs_ : format_specs()); return out(); } @@ -1392,8 +1450,8 @@ class arg_formatter_base { arg_formatter_base &formatter; char_type value; - char_spec_handler(arg_formatter_base& f, char_type val) - : formatter(f), value(val) {} + char_spec_handler(arg_formatter_base &f, char_type val) + : formatter(f), value(val) {} void on_int() { if (formatter.specs_) @@ -1409,23 +1467,23 @@ class arg_formatter_base { const char_type *value; cstring_spec_handler(arg_formatter_base &f, const char_type *val) - : formatter(f), value(val) {} + : formatter(f), value(val) {} void on_string() { formatter.write(value); } void on_pointer() { formatter.write_pointer(value); } }; iterator operator()(const char_type *value) { - if (!specs_) return write(value), out(); - internal::handle_cstring_type_spec( - specs_->type, cstring_spec_handler(*this, value)); + if (!specs_) + return write(value), out(); + internal::handle_cstring_type_spec(specs_->type, + cstring_spec_handler(*this, value)); return out(); } iterator operator()(basic_string_view value) { if (specs_) { - internal::check_string_type_spec( - specs_->type, internal::error_handler()); + internal::check_string_type_spec(specs_->type, internal::error_handler()); writer_.write(value, *specs_); } else { writer_.write(value); @@ -1449,8 +1507,9 @@ FMT_CONSTEXPR bool is_name_start(Char c) { // Parses the range [begin, end) as an unsigned integer. This function assumes // that the range is non-empty and the first character is a digit. template -FMT_CONSTEXPR unsigned parse_nonnegative_int( - const Char *&begin, const Char *end, ErrorHandler &&eh) { +FMT_CONSTEXPR unsigned parse_nonnegative_int(const Char *&begin, + const Char *end, + ErrorHandler &&eh) { assert(begin != end && '0' <= *begin && *begin <= '9'); if (*begin == '0') { ++begin; @@ -1475,12 +1534,12 @@ FMT_CONSTEXPR unsigned parse_nonnegative_int( } template -class custom_formatter: public function { +class custom_formatter : public function { private: Context &ctx_; public: - explicit custom_formatter(Context &ctx): ctx_(ctx) {} + explicit custom_formatter(Context &ctx) : ctx_(ctx) {} bool operator()(typename basic_format_arg::handle h) const { h.format(ctx_); @@ -1488,7 +1547,9 @@ class custom_formatter: public function { } template - bool operator()(T) const { return false; } + bool operator()(T) const { + return false; + } }; template @@ -1500,22 +1561,23 @@ struct is_integer { }; template -class width_checker: public function { +class width_checker : public function { public: explicit FMT_CONSTEXPR width_checker(ErrorHandler &eh) : handler_(eh) {} template FMT_CONSTEXPR - typename std::enable_if< - is_integer::value, unsigned long long>::type operator()(T value) { + typename std::enable_if::value, unsigned long long>::type + operator()(T value) { if (is_negative(value)) handler_.on_error("negative width"); return static_cast(value); } template - FMT_CONSTEXPR typename std::enable_if< - !is_integer::value, unsigned long long>::type operator()(T) { + FMT_CONSTEXPR + typename std::enable_if::value, unsigned long long>::type + operator()(T) { handler_.on_error("width is not integer"); return 0; } @@ -1525,21 +1587,23 @@ class width_checker: public function { }; template -class precision_checker: public function { +class precision_checker : public function { public: explicit FMT_CONSTEXPR precision_checker(ErrorHandler &eh) : handler_(eh) {} template - FMT_CONSTEXPR typename std::enable_if< - is_integer::value, unsigned long long>::type operator()(T value) { + FMT_CONSTEXPR + typename std::enable_if::value, unsigned long long>::type + operator()(T value) { if (is_negative(value)) handler_.on_error("negative precision"); return static_cast(value); } template - FMT_CONSTEXPR typename std::enable_if< - !is_integer::value, unsigned long long>::type operator()(T) { + FMT_CONSTEXPR + typename std::enable_if::value, unsigned long long>::type + operator()(T) { handler_.on_error("precision is not integer"); return 0; } @@ -1552,10 +1616,11 @@ class precision_checker: public function { template class specs_setter { public: - explicit FMT_CONSTEXPR specs_setter(basic_format_specs &specs): - specs_(specs) {} + explicit FMT_CONSTEXPR specs_setter(basic_format_specs &specs) + : specs_(specs) {} - FMT_CONSTEXPR specs_setter(const specs_setter &other): specs_(other.specs_) {} + FMT_CONSTEXPR specs_setter(const specs_setter &other) + : specs_(other.specs_) {} FMT_CONSTEXPR void on_align(alignment align) { specs_.align_ = align; } FMT_CONSTEXPR void on_fill(Char fill) { specs_.fill_ = fill; } @@ -1588,11 +1653,11 @@ class specs_setter { template class specs_checker : public Handler { public: - FMT_CONSTEXPR specs_checker(const Handler& handler, internal::type arg_type) - : Handler(handler), arg_type_(arg_type) {} + FMT_CONSTEXPR specs_checker(const Handler &handler, internal::type arg_type) + : Handler(handler), arg_type_(arg_type) {} FMT_CONSTEXPR specs_checker(const specs_checker &other) - : Handler(other), arg_type_(other.arg_type_) {} + : Handler(other), arg_type_(other.arg_type_) {} FMT_CONSTEXPR void on_align(alignment align) { if (align == ALIGN_NUMERIC) @@ -1647,10 +1712,10 @@ class specs_checker : public Handler { internal::type arg_type_; }; -template