Skip to content

Commit

Permalink
Make std::byte formattabe (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Dec 3, 2020
1 parent 683a745 commit 4a6eadb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3538,7 +3538,7 @@ struct formatter<T, Char,
struct formatter<Type, Char> : formatter<Base, Char> { \
template <typename FormatContext> \
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); \
} \
}

Expand All @@ -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::nullptr_t, const void*);
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>
struct formatter<void*, Char> : formatter<const void*, Char> {
Expand Down
7 changes: 7 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,13 @@ TEST(FormatTest, JoinArg) {
#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) {
return fmt::format("{}", value);
}
Expand Down

0 comments on commit 4a6eadb

Please sign in to comment.