Skip to content

Commit

Permalink
Cleanup format API
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Sep 22, 2024
1 parent 9282222 commit b426056
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,17 @@ template <> inline auto decimal_point(locale_ref loc) -> wchar_t {
return decimal_point_impl<wchar_t>(loc);
}

#ifndef FMT_HEADER_ONLY
FMT_BEGIN_EXPORT
extern template FMT_API auto thousands_sep_impl<char>(locale_ref)
-> thousands_sep_result<char>;
extern template FMT_API auto thousands_sep_impl<wchar_t>(locale_ref)
-> thousands_sep_result<wchar_t>;
extern template FMT_API auto decimal_point_impl(locale_ref) -> char;
extern template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
FMT_END_EXPORT
#endif // FMT_HEADER_ONLY

// Compares two characters for equality.
template <typename Char> auto equal2(const Char* lhs, const char* rhs) -> bool {
return lhs[0] == Char(rhs[0]) && lhs[1] == Char(rhs[1]);
Expand Down Expand Up @@ -3804,19 +3815,6 @@ using fmt::report_error;
FMT_API void report_error(format_func func, int error_code,
const char* message) noexcept;

FMT_BEGIN_EXPORT

#ifndef FMT_HEADER_ONLY
extern template FMT_API auto thousands_sep_impl<char>(locale_ref)
-> thousands_sep_result<char>;
extern template FMT_API auto thousands_sep_impl<wchar_t>(locale_ref)
-> thousands_sep_result<wchar_t>;
extern template FMT_API auto decimal_point_impl(locale_ref) -> char;
extern template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
#endif // FMT_HEADER_ONLY

FMT_END_EXPORT

template <typename T, typename Char, type TYPE>
template <typename FormatContext>
FMT_CONSTEXPR auto native_formatter<T, Char, TYPE>::format(
Expand All @@ -3834,17 +3832,6 @@ FMT_CONSTEXPR auto native_formatter<T, Char, TYPE>::format(

FMT_BEGIN_EXPORT

template <typename T, typename Char>
struct formatter<T, Char, void_t<detail::format_as_result<T>>>
: formatter<detail::format_as_result<T>, Char> {
template <typename FormatContext>
FMT_CONSTEXPR auto format(const T& value, FormatContext& ctx) const
-> decltype(ctx.out()) {
auto&& val = format_as(value); // Make an lvalue reference for format.
return formatter<detail::format_as_result<T>, Char>::format(val, ctx);
}
};

#define FMT_FORMAT_AS(Type, Base) \
template <typename Char> \
struct formatter<Type, Char> : formatter<Base, Char> { \
Expand Down Expand Up @@ -3884,6 +3871,17 @@ struct formatter<detail::float128, Char>
: detail::native_formatter<detail::float128, Char,
detail::type::float_type> {};

template <typename T, typename Char>
struct formatter<T, Char, void_t<detail::format_as_result<T>>>
: formatter<detail::format_as_result<T>, Char> {
template <typename FormatContext>
FMT_CONSTEXPR auto format(const T& value, FormatContext& ctx) const
-> decltype(ctx.out()) {
auto&& val = format_as(value); // Make an lvalue reference for format.
return formatter<detail::format_as_result<T>, Char>::format(val, ctx);
}
};

/**
* Converts `p` to `const void*` for pointer formatting.
*
Expand Down

0 comments on commit b426056

Please sign in to comment.