Skip to content

Commit

Permalink
Backport a fix to C++20 partial specialization issue
Browse files Browse the repository at this point in the history
Summary: Backport a fix to fmtlib/fmt#2769.

Reviewed By: aandreyeu

Differential Revision: D37077479

fbshipit-source-id: 6f9d716c47784717c4aa36eba89498639eb3503a
  • Loading branch information
EduardoCostaom authored and facebook-github-bot committed Jun 10, 2022
1 parent f1ef7eb commit 8b009dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
22 changes: 22 additions & 0 deletions deps/fmt/include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,28 @@ struct formatter<T, Char,
-> decltype(ctx.out());
};

#define FMT_FORMAT_AS(Type, Base) \
template <typename Char> \
struct formatter<Type, Char> : formatter<Base, Char> { \
template <typename FormatContext> \
auto format(Type const& val, FormatContext& ctx) const \
-> decltype(ctx.out()) { \
return formatter<Base, Char>::format(static_cast<Base>(val), ctx); \
} \
}

FMT_FORMAT_AS(signed char, int);
FMT_FORMAT_AS(unsigned char, unsigned);
FMT_FORMAT_AS(short, int);
FMT_FORMAT_AS(unsigned short, unsigned);
FMT_FORMAT_AS(long, long long);
FMT_FORMAT_AS(unsigned long, unsigned long long);
FMT_FORMAT_AS(Char*, const Char*);
FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
FMT_FORMAT_AS(std::nullptr_t, const void*);
FMT_FORMAT_AS(detail::byte, unsigned char);
FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>);

template <typename Char> struct basic_runtime { basic_string_view<Char> str; };

/** A compile-time format string. */
Expand Down
22 changes: 0 additions & 22 deletions deps/fmt/include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2581,28 +2581,6 @@ formatter<T, Char,
return detail::write<Char>(ctx.out(), val, specs_, ctx.locale());
}

#define FMT_FORMAT_AS(Type, Base) \
template <typename Char> \
struct formatter<Type, Char> : formatter<Base, Char> { \
template <typename FormatContext> \
auto format(Type const& val, FormatContext& ctx) const \
-> decltype(ctx.out()) { \
return formatter<Base, Char>::format(static_cast<Base>(val), ctx); \
} \
}

FMT_FORMAT_AS(signed char, int);
FMT_FORMAT_AS(unsigned char, unsigned);
FMT_FORMAT_AS(short, int);
FMT_FORMAT_AS(unsigned short, unsigned);
FMT_FORMAT_AS(long, long long);
FMT_FORMAT_AS(unsigned long, unsigned long long);
FMT_FORMAT_AS(Char*, const Char*);
FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
FMT_FORMAT_AS(std::nullptr_t, const void*);
FMT_FORMAT_AS(detail::byte, unsigned char);
FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>);

template <typename Char>
struct formatter<void*, Char> : formatter<const void*, Char> {
template <typename FormatContext>
Expand Down

0 comments on commit 8b009dd

Please sign in to comment.