diff --git a/doc/api.md b/doc/api.md index bf0df731..40b2b403 100644 --- a/doc/api.md +++ b/doc/api.md @@ -410,11 +410,11 @@ locale: that take `std::locale` as a parameter. The locale type is a template parameter to avoid the expensive `` include. -::: format(const Locale&, format_string, T&&...) +::: format(detail::locale_ref, format_string, T&&...) -::: format_to(OutputIt, const Locale&, format_string, T&&...) +::: format_to(OutputIt, detail::locale_ref, format_string, T&&...) -::: formatted_size(const Locale&, format_string, T&&...) +::: formatted_size(detail::locale_ref, format_string, T&&...) ### Legacy Compile-Time Checks diff --git a/include/fmt/base.h b/include/fmt/base.h index b36faabc..c9b18cac 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2220,9 +2220,12 @@ struct locale_ref { public: constexpr locale_ref() : locale_(nullptr) {} - template explicit locale_ref(const Locale& loc); + + template + locale_ref(const Locale& loc); + explicit operator bool() const noexcept { return locale_ != nullptr; } -#endif +#endif // FMT_USE_LOCALE template auto get() const -> Locale; }; diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 40a34149..5bf952c3 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -84,7 +84,7 @@ using std::locale; using std::numpunct; using std::use_facet; -template +template > locale_ref::locale_ref(const Locale& loc) : locale_(&loc) { static_assert(std::is_same::value, ""); } diff --git a/include/fmt/format.h b/include/fmt/format.h index f64aa9ce..13c8f58f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -796,11 +796,6 @@ using is_double_double = bool_constant::digits == 106>; # define FMT_USE_FULL_CACHE_DRAGONBOX 0 #endif -template -struct is_locale : std::false_type {}; -template -struct is_locale> : std::true_type {}; - // An allocator that uses malloc/free to allow removing dependency on the C++ // standard libary runtime. template struct allocator { @@ -4213,47 +4208,41 @@ FMT_API void format_system_error(detail::buffer& out, int error_code, // Can be used to report errors from destructors. FMT_API void report_system_error(int error_code, const char* message) noexcept; -template ::value)> -auto vformat(const Locale& loc, string_view fmt, format_args args) +inline auto vformat(detail::locale_ref loc, string_view fmt, format_args args) -> std::string { auto buf = memory_buffer(); - detail::vformat_to(buf, fmt, args, detail::locale_ref(loc)); + detail::vformat_to(buf, fmt, args, loc); return {buf.data(), buf.size()}; } -template ::value)> -FMT_INLINE auto format(const Locale& loc, format_string fmt, T&&... args) - -> std::string { - return fmt::vformat(loc, fmt.str, vargs{{args...}}); +template +FMT_INLINE auto format(detail::locale_ref loc, format_string fmt, + T&&... args) -> std::string { + return vformat(loc, fmt.str, vargs{{args...}}); } -template ::value&& - detail::is_locale::value)> -auto vformat_to(OutputIt out, const Locale& loc, string_view fmt, +template ::value)> +auto vformat_to(OutputIt out, detail::locale_ref loc, string_view fmt, format_args args) -> OutputIt { auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, fmt, args, detail::locale_ref(loc)); + detail::vformat_to(buf, fmt, args, loc); return detail::get_iterator(buf, out); } -template ::value&& - detail::is_locale::value)> -FMT_INLINE auto format_to(OutputIt out, const Locale& loc, +template ::value)> +FMT_INLINE auto format_to(OutputIt out, detail::locale_ref loc, format_string fmt, T&&... args) -> OutputIt { return fmt::vformat_to(out, loc, fmt.str, vargs{{args...}}); } -template ::value)> -FMT_NODISCARD FMT_INLINE auto formatted_size(const Locale& loc, +template +FMT_NODISCARD FMT_INLINE auto formatted_size(detail::locale_ref loc, format_string fmt, T&&... args) -> size_t { auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, fmt.str, vargs{{args...}}, - detail::locale_ref(loc)); + detail::vformat_to(buf, fmt.str, vargs{{args...}}, loc); return buf.count(); } diff --git a/include/fmt/std.h b/include/fmt/std.h index 722b6ad9..839e1714 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -433,8 +433,8 @@ template <> struct formatter { } template - FMT_CONSTEXPR20 auto format(const std::error_code& ec, FormatContext& ctx) const - -> decltype(ctx.out()) { + FMT_CONSTEXPR20 auto format(const std::error_code& ec, + FormatContext& ctx) const -> decltype(ctx.out()) { auto specs = specs_; detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, ctx); diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index da593d33..08f11231 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -191,11 +191,9 @@ auto format(const S& fmt, T&&... args) -> std::basic_string { fmt::make_format_args>(args...)); } -template , - FMT_ENABLE_IF(detail::is_locale::value&& - detail::is_exotic_char::value)> -inline auto vformat(const Locale& loc, const S& fmt, +template , + FMT_ENABLE_IF(detail::is_exotic_char::value)> +inline auto vformat(detail::locale_ref loc, const S& fmt, typename detail::vformat_args::type args) -> std::basic_string { auto buf = basic_memory_buffer(); @@ -204,11 +202,10 @@ inline auto vformat(const Locale& loc, const S& fmt, return {buf.data(), buf.size()}; } -template , - FMT_ENABLE_IF(detail::is_locale::value&& - detail::is_exotic_char::value)> -inline auto format(const Locale& loc, const S& fmt, T&&... args) + FMT_ENABLE_IF(detail::is_exotic_char::value)> +inline auto format(detail::locale_ref loc, const S& fmt, T&&... args) -> std::basic_string { return vformat(loc, detail::to_string_view(fmt), fmt::make_format_args>(args...)); @@ -235,12 +232,11 @@ inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt { fmt::make_format_args>(args...)); } -template , FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_locale::value&& - detail::is_exotic_char::value)> -inline auto vformat_to(OutputIt out, const Locale& loc, const S& fmt, + detail::is_exotic_char::value)> +inline auto vformat_to(OutputIt out, detail::locale_ref loc, const S& fmt, typename detail::vformat_args::type args) -> OutputIt { auto&& buf = detail::get_buffer(out); @@ -248,12 +244,11 @@ inline auto vformat_to(OutputIt out, const Locale& loc, const S& fmt, return detail::get_iterator(buf, out); } -template , bool enable = detail::is_output_iterator::value && - detail::is_locale::value && detail::is_exotic_char::value> -inline auto format_to(OutputIt out, const Locale& loc, const S& fmt, +inline auto format_to(OutputIt out, detail::locale_ref loc, const S& fmt, T&&... args) -> typename std::enable_if::type { return vformat_to(out, loc, detail::to_string_view(fmt),