Skip to content

Commit 891c9a7

Browse files
committed
Cleanup format API
1 parent 9282222 commit 891c9a7

File tree

3 files changed

+44
-48
lines changed

3 files changed

+44
-48
lines changed

include/fmt/format-inl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
6363
FMT_ASSERT(out.size() <= inline_buffer_size, "");
6464
}
6565

66-
FMT_FUNC void report_error(format_func func, int error_code,
67-
const char* message) noexcept {
66+
FMT_FUNC void do_report_error(format_func func, int error_code,
67+
const char* message) noexcept {
6868
memory_buffer full_message;
6969
func(full_message, error_code, message);
7070
// Don't use fwrite_all because the latter may throw.
@@ -1434,7 +1434,7 @@ FMT_FUNC void format_system_error(detail::buffer<char>& out, int error_code,
14341434

14351435
FMT_FUNC void report_system_error(int error_code,
14361436
const char* message) noexcept {
1437-
report_error(format_system_error, error_code, message);
1437+
do_report_error(format_system_error, error_code, message);
14381438
}
14391439

14401440
FMT_FUNC auto vformat(string_view fmt, format_args args) -> std::string {

include/fmt/format.h

+40-44
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,17 @@ template <> inline auto decimal_point(locale_ref loc) -> wchar_t {
12971297
return decimal_point_impl<wchar_t>(loc);
12981298
}
12991299

1300+
#ifndef FMT_HEADER_ONLY
1301+
FMT_BEGIN_EXPORT
1302+
extern template FMT_API auto thousands_sep_impl<char>(locale_ref)
1303+
-> thousands_sep_result<char>;
1304+
extern template FMT_API auto thousands_sep_impl<wchar_t>(locale_ref)
1305+
-> thousands_sep_result<wchar_t>;
1306+
extern template FMT_API auto decimal_point_impl(locale_ref) -> char;
1307+
extern template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
1308+
FMT_END_EXPORT
1309+
#endif // FMT_HEADER_ONLY
1310+
13001311
// Compares two characters for equality.
13011312
template <typename Char> auto equal2(const Char* lhs, const char* rhs) -> bool {
13021313
return lhs[0] == Char(rhs[0]) && lhs[1] == Char(rhs[1]);
@@ -3779,44 +3790,13 @@ template <typename Char> struct format_handler {
37793790
FMT_NORETURN void on_error(const char* message) { report_error(message); }
37803791
};
37813792

3782-
// DEPRECATED!
3783-
template <typename Char = char> struct vformat_args {
3784-
using type = basic_format_args<buffered_context<Char>>;
3785-
};
3786-
template <> struct vformat_args<char> {
3787-
using type = format_args;
3788-
};
3789-
3790-
template <typename Char>
3791-
void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
3792-
typename vformat_args<Char>::type args, locale_ref loc = {}) {
3793-
auto out = basic_appender<Char>(buf);
3794-
parse_format_string(
3795-
fmt, format_handler<Char>{parse_context<Char>(fmt), {out, args, loc}});
3796-
}
3797-
37983793
using format_func = void (*)(detail::buffer<char>&, int, const char*);
3794+
FMT_API void do_report_error(format_func func, int error_code,
3795+
const char* message) noexcept;
37993796

38003797
FMT_API void format_error_code(buffer<char>& out, int error_code,
38013798
string_view message) noexcept;
38023799

3803-
using fmt::report_error;
3804-
FMT_API void report_error(format_func func, int error_code,
3805-
const char* message) noexcept;
3806-
3807-
FMT_BEGIN_EXPORT
3808-
3809-
#ifndef FMT_HEADER_ONLY
3810-
extern template FMT_API auto thousands_sep_impl<char>(locale_ref)
3811-
-> thousands_sep_result<char>;
3812-
extern template FMT_API auto thousands_sep_impl<wchar_t>(locale_ref)
3813-
-> thousands_sep_result<wchar_t>;
3814-
extern template FMT_API auto decimal_point_impl(locale_ref) -> char;
3815-
extern template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
3816-
#endif // FMT_HEADER_ONLY
3817-
3818-
FMT_END_EXPORT
3819-
38203800
template <typename T, typename Char, type TYPE>
38213801
template <typename FormatContext>
38223802
FMT_CONSTEXPR auto native_formatter<T, Char, TYPE>::format(
@@ -3830,21 +3810,26 @@ FMT_CONSTEXPR auto native_formatter<T, Char, TYPE>::format(
38303810
specs_.precision_ref, ctx);
38313811
return write<Char>(ctx.out(), val, specs, ctx.locale());
38323812
}
3813+
3814+
// DEPRECATED!
3815+
template <typename Char = char> struct vformat_args {
3816+
using type = basic_format_args<buffered_context<Char>>;
3817+
};
3818+
template <> struct vformat_args<char> {
3819+
using type = format_args;
3820+
};
3821+
3822+
template <typename Char>
3823+
void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
3824+
typename vformat_args<Char>::type args, locale_ref loc = {}) {
3825+
auto out = basic_appender<Char>(buf);
3826+
parse_format_string(
3827+
fmt, format_handler<Char>{parse_context<Char>(fmt), {out, args, loc}});
3828+
}
38333829
} // namespace detail
38343830

38353831
FMT_BEGIN_EXPORT
38363832

3837-
template <typename T, typename Char>
3838-
struct formatter<T, Char, void_t<detail::format_as_result<T>>>
3839-
: formatter<detail::format_as_result<T>, Char> {
3840-
template <typename FormatContext>
3841-
FMT_CONSTEXPR auto format(const T& value, FormatContext& ctx) const
3842-
-> decltype(ctx.out()) {
3843-
auto&& val = format_as(value); // Make an lvalue reference for format.
3844-
return formatter<detail::format_as_result<T>, Char>::format(val, ctx);
3845-
}
3846-
};
3847-
38483833
#define FMT_FORMAT_AS(Type, Base) \
38493834
template <typename Char> \
38503835
struct formatter<Type, Char> : formatter<Base, Char> { \
@@ -3884,6 +3869,17 @@ struct formatter<detail::float128, Char>
38843869
: detail::native_formatter<detail::float128, Char,
38853870
detail::type::float_type> {};
38863871

3872+
template <typename T, typename Char>
3873+
struct formatter<T, Char, void_t<detail::format_as_result<T>>>
3874+
: formatter<detail::format_as_result<T>, Char> {
3875+
template <typename FormatContext>
3876+
FMT_CONSTEXPR auto format(const T& value, FormatContext& ctx) const
3877+
-> decltype(ctx.out()) {
3878+
auto&& val = format_as(value); // Make an lvalue reference for format.
3879+
return formatter<detail::format_as_result<T>, Char>::format(val, ctx);
3880+
}
3881+
};
3882+
38873883
/**
38883884
* Converts `p` to `const void*` for pointer formatting.
38893885
*

src/os.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void detail::format_windows_error(detail::buffer<char>& out, int error_code,
160160
}
161161

162162
void report_windows_error(int error_code, const char* message) noexcept {
163-
report_error(detail::format_windows_error, error_code, message);
163+
do_report_error(detail::format_windows_error, error_code, message);
164164
}
165165
#endif // _WIN32
166166

0 commit comments

Comments
 (0)