Skip to content

Commit

Permalink
fix byte formatting with FMT_COMPILE, use __cpp_lib_byte macro
Browse files Browse the repository at this point in the history
  • Loading branch information
alexezeder committed Dec 22, 2020
1 parent cc4a995 commit 0e89ada
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2112,8 +2112,14 @@ FMT_CONSTEXPR OutputIt write(OutputIt out, T value) {
}

template <typename Char, typename OutputIt, typename T,
#ifdef __cpp_lib_byte
FMT_ENABLE_IF(std::is_enum<T>::value &&
!std::is_same<T, Char>::value &&
!std::is_same<T, std::byte>::value)>
#else
FMT_ENABLE_IF(std::is_enum<T>::value &&
!std::is_same<T, Char>::value)>
#endif
FMT_CONSTEXPR OutputIt write(OutputIt out, T value) {
return write<Char>(
out, static_cast<typename std::underlying_type<T>::type>(value));
Expand Down Expand Up @@ -3562,7 +3568,7 @@ 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
#ifdef __cpp_lib_byte
FMT_FORMAT_AS(std::byte, unsigned);
#endif

Expand Down
2 changes: 1 addition & 1 deletion test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ TEST(FormatTest, JoinArg) {
#endif
}

#if __cplusplus >= 201703L
#ifdef __cpp_lib_byte
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, ", ")));
Expand Down

0 comments on commit 0e89ada

Please sign in to comment.