Enable format_as for non-integral types

This commit is contained in:
Victor Zverovich 2023-01-02 10:43:08 -08:00
parent 09ed1ddb9c
commit b7535365b2
2 changed files with 5 additions and 1 deletions

View File

@ -1350,7 +1350,7 @@ inline auto format_as(std::byte b) -> unsigned char {
template <typename T> struct has_format_as {
template <typename U, typename V = decltype(format_as(U())),
FMT_ENABLE_IF(std::is_enum<U>::value&& std::is_integral<V>::value)>
FMT_ENABLE_IF(std::is_enum<U>::value)>
static auto check(U*) -> std::true_type;
static auto check(...) -> std::false_type;

View File

@ -677,6 +677,9 @@ namespace test {
enum class scoped_enum_as_int {};
auto format_as(scoped_enum_as_int) -> int { return 42; }
enum class scoped_enum_as_string {};
auto format_as(scoped_enum_as_string) -> fmt::string_view { return "foo"; }
struct convertible_to_enum {
operator scoped_enum_as_int() const { return {}; }
};
@ -734,6 +737,7 @@ TEST(core_test, format_to) {
TEST(core_test, format_as) {
EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_int()), "42");
EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_string()), "foo");
}
#ifdef __cpp_lib_byte