diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 00bea734..ccffa645 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -505,13 +505,14 @@ struct range_formatter< enum class range_format { disabled, map, set, sequence, string, debug_string }; namespace detail { -template struct range_format_kind_ { - static constexpr auto value = std::is_same, T>::value - ? range_format::disabled - : is_map::value ? range_format::map - : is_set::value ? range_format::set - : range_format::sequence; -}; +template +struct range_format_kind_ + : std::integral_constant, T>::value + ? range_format::disabled + : is_map::value ? range_format::map + : is_set::value ? range_format::set + : range_format::sequence> {}; template struct range_default_formatter; diff --git a/test/ranges-test.cc b/test/ranges-test.cc index e4a2d0e3..6cd28fab 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -179,15 +179,20 @@ TEST(ranges_test, format_to) { EXPECT_STREQ(buf, "[1, 2, 3]"); } -struct path_like { +template struct path_like { const path_like* begin() const; const path_like* end() const; - operator std::string() const; + operator std::basic_string() const; }; -TEST(ranges_test, path_like) { - EXPECT_FALSE((fmt::is_range::value)); +TEST(ranges_test, disabled_range_formatting_of_path) { + // Range formatting of path is disabled because of infinite recursion + // (path element is itself a path). + EXPECT_EQ((fmt::range_format_kind, char>::value), + fmt::range_format::disabled); + EXPECT_EQ((fmt::range_format_kind, char>::value), + fmt::range_format::disabled); } // A range that provides non-const only begin()/end() to test fmt::join