From 9408c2ae8c264f2c94495db73251f75fcc35cad0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 7 Sep 2024 07:40:37 -0700 Subject: [PATCH] Readd support for FMT_BUILTIN_TYPES --- include/fmt/base.h | 44 ++++++++++++++++++++++++------------------- include/fmt/ostream.h | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index fe297410..ef815276 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2193,6 +2193,12 @@ template struct custom_value { void (*format)(void* arg, parse_context& parse_ctx, Context& ctx); }; +#if !FMT_BUILTIN_TYPES +# define FMT_BUILTIN , monostate +#else +# define FMT_BUILTIN +#endif + // A formatting argument value. template class value { public: @@ -2217,41 +2223,42 @@ template class value { named_arg_value named_args; }; - constexpr FMT_ALWAYS_INLINE value() : no_value() {} - constexpr FMT_ALWAYS_INLINE value(int val) : int_value(val) {} - constexpr FMT_ALWAYS_INLINE value(unsigned val) : uint_value(val) {} - constexpr FMT_ALWAYS_INLINE value(long long val) : long_long_value(val) {} - constexpr FMT_ALWAYS_INLINE value(unsigned long long val) + constexpr FMT_INLINE value() : no_value() {} + constexpr FMT_INLINE value(int val) : int_value(val) {} + constexpr FMT_INLINE value(unsigned val FMT_BUILTIN) : uint_value(val) {} + constexpr FMT_INLINE value(long long val FMT_BUILTIN) + : long_long_value(val) {} + constexpr FMT_INLINE value(unsigned long long val FMT_BUILTIN) : ulong_long_value(val) {} - FMT_ALWAYS_INLINE value(int128_opt val) : int128_value(val) {} - FMT_ALWAYS_INLINE value(uint128_opt val) : uint128_value(val) {} - constexpr FMT_ALWAYS_INLINE value(float val) : float_value(val) {} - constexpr FMT_ALWAYS_INLINE value(double val) : double_value(val) {} - FMT_ALWAYS_INLINE value(long double val) : long_double_value(val) {} - constexpr FMT_ALWAYS_INLINE value(bool val) : bool_value(val) {} - constexpr FMT_ALWAYS_INLINE value(char_type val) : char_value(val) {} - FMT_CONSTEXPR FMT_ALWAYS_INLINE value(const char_type* val) { + FMT_INLINE value(int128_opt val FMT_BUILTIN) : int128_value(val) {} + FMT_INLINE value(uint128_opt val FMT_BUILTIN) : uint128_value(val) {} + constexpr FMT_INLINE value(float val FMT_BUILTIN) : float_value(val) {} + constexpr FMT_INLINE value(double val FMT_BUILTIN) : double_value(val) {} + FMT_INLINE value(long double val FMT_BUILTIN) : long_double_value(val) {} + constexpr FMT_INLINE value(bool val FMT_BUILTIN) : bool_value(val) {} + constexpr FMT_INLINE value(char_type val FMT_BUILTIN) : char_value(val) {} + FMT_CONSTEXPR FMT_INLINE value(const char_type* val FMT_BUILTIN) { string.data = val; if (is_constant_evaluated()) string.size = {}; } - FMT_CONSTEXPR FMT_ALWAYS_INLINE value(basic_string_view val) { + FMT_CONSTEXPR FMT_INLINE value(basic_string_view val FMT_BUILTIN) { string.data = val.data(); string.size = val.size(); } - FMT_ALWAYS_INLINE value(const void* val) : pointer(val) {} + FMT_INLINE value(const void* val FMT_BUILTIN) : pointer(val) {} // We can't use mapped_t because of a bug in MSVC 2017. template ::map( std::declval()))>::value)> - FMT_CONSTEXPR20 FMT_ALWAYS_INLINE value(T&& val) { + FMT_CONSTEXPR20 FMT_INLINE value(T&& val) { *this = arg_mapper::map(val); } template ::map( std::declval()))>::value)> - FMT_CONSTEXPR20 FMT_ALWAYS_INLINE value(T&& val) { + FMT_CONSTEXPR20 FMT_INLINE value(T&& val) { // Use enum instead of constexpr because the latter may generate code. enum { formattable_char = !std::is_same::value }; static_assert(formattable_char, "mixing character types is disallowed"); @@ -2347,7 +2354,6 @@ struct locale_ref { public: constexpr locale_ref() : locale_(nullptr) {} template explicit locale_ref(const Locale& loc); - explicit operator bool() const noexcept { return locale_ != nullptr; } #endif @@ -2991,7 +2997,7 @@ auto vformat_to(char (&out)[N], string_view fmt, format_args args) template FMT_INLINE auto format_to(char (&out)[N], format_string fmt, T&&... args) -> format_to_result { - auto result = fmt::format_to_n(out, N, fmt, static_cast(args)...); + auto result = vformat_to_n(out, N, fmt, vargs{{args...}}); return {result.out, result.size > N}; } diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 8ae1d5a7..71f51904 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -46,7 +46,7 @@ auto get_file(std::filebuf&) -> FILE*; template void write_buffer(std::basic_ostream& os, buffer& buf) { const Char* buf_data = buf.data(); - using unsigned_streamsize =make_unsigned_t; + using unsigned_streamsize = make_unsigned_t; unsigned_streamsize size = buf.size(); unsigned_streamsize max_size = to_unsigned(max_value()); do {