Skip to content

Commit

Permalink
Move built-in formatter specialization to core
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Feb 16, 2022
1 parent 161059d commit a1ea3e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 21 additions & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3027,6 +3027,27 @@ 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::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
21 changes: 0 additions & 21 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2762,27 +2762,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::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 a1ea3e0

Please sign in to comment.