Workaround an issue with std::filesystem::path being an infinitely deep range (#1268)

This commit is contained in:
Victor Zverovich 2019-08-21 11:22:59 -07:00
parent 2aae6b120c
commit b2d4ca1546
2 changed files with 17 additions and 3 deletions

View File

@ -242,13 +242,16 @@ struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
}
};
template <typename T> struct is_range {
template <typename T, typename Char> struct is_range {
static FMT_CONSTEXPR_DECL const bool value =
internal::is_range_<T>::value && !internal::is_like_std_string<T>::value;
internal::is_range_<T>::value &&
!internal::is_like_std_string<T>::value &&
!std::is_convertible<T, std::basic_string<Char>>::value;
};
template <typename RangeT, typename Char>
struct formatter<RangeT, Char, enable_if_t<fmt::is_range<RangeT>::value>> {
struct formatter<RangeT, Char,
enable_if_t<fmt::is_range<RangeT, Char>::value>> {
formatting_range<Char> formatting;
template <typename ParseContext>

View File

@ -87,5 +87,16 @@ TEST(RangesTest, FormatTo) {
EXPECT_STREQ(buf, "{1, 2, 3}");
}
struct path_like {
const path_like* begin() const;
const path_like* end() const;
operator std::string() const;
};
TEST(RangesTest, PathLike) {
EXPECT_FALSE((fmt::is_range<path_like, char>::value));
}
#endif // (__cplusplus > 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >
// 201402L && _MSC_VER >= 1910)