Make std::byte formattabe (#1981)

This commit is contained in:
Victor Zverovich 2020-12-03 08:50:28 -08:00
parent 683a74501f
commit 4a6eadbde0
2 changed files with 11 additions and 1 deletions

View File

@ -3538,7 +3538,7 @@ struct formatter<T, Char,
struct formatter<Type, Char> : formatter<Base, Char> { \ struct formatter<Type, Char> : formatter<Base, Char> { \
template <typename FormatContext> \ template <typename FormatContext> \
auto format(Type const& val, FormatContext& ctx) -> decltype(ctx.out()) { \ auto format(Type const& val, FormatContext& ctx) -> decltype(ctx.out()) { \
return formatter<Base, Char>::format(val, ctx); \ return formatter<Base, Char>::format(static_cast<Base>(val), ctx); \
} \ } \
} }
@ -3552,6 +3552,9 @@ FMT_FORMAT_AS(Char*, const Char*);
FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>); FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
FMT_FORMAT_AS(std::nullptr_t, const void*); FMT_FORMAT_AS(std::nullptr_t, const void*);
FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>); FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>);
#if __cplusplus >= 201703L
FMT_FORMAT_AS(std::byte, unsigned);
#endif
template <typename Char> template <typename Char>
struct formatter<void*, Char> : formatter<const void*, Char> { struct formatter<void*, Char> : formatter<const void*, Char> {

View File

@ -1762,6 +1762,13 @@ TEST(FormatTest, JoinArg) {
#endif #endif
} }
#if __cplusplus >= 201703L
TEST(FormatTest, JoinBytes) {
std::vector<std::byte> v = {std::byte(1), std::byte(2), std::byte(3)};
EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join(v, ", ")));
}
#endif
template <typename T> std::string str(const T& value) { template <typename T> std::string str(const T& value) {
return fmt::format("{}", value); return fmt::format("{}", value);
} }