Skip to content

Commit 9c53225

Browse files
committed
fmtlib#2954: As workaround for older MSVC compilers split formatter<std::filesystem::path> partial template specialization into two explicit specialization.
1 parent 4ccada9 commit 9c53225

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

include/fmt/std.h

+28
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ inline void write_escaped_path<std::filesystem::path::value_type>(
5050

5151
} // namespace detail
5252

53+
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920
5354
template <typename Char>
5455
struct formatter<std::filesystem::path, Char>
5556
: formatter<basic_string_view<Char>> {
@@ -62,6 +63,33 @@ struct formatter<std::filesystem::path, Char>
6263
basic_string_view<Char>(quoted.data(), quoted.size()), ctx);
6364
}
6465
};
66+
#else
67+
// Workaround for MSVC 2017 and earlier.
68+
template <>
69+
struct formatter<std::filesystem::path, char>
70+
: formatter<basic_string_view<char>> {
71+
template <typename FormatContext>
72+
auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
73+
typename FormatContext::iterator {
74+
basic_memory_buffer<char> quoted;
75+
detail::write_escaped_path(quoted, p);
76+
return formatter<basic_string_view<char>>::format(
77+
basic_string_view<char>(quoted.data(), quoted.size()), ctx);
78+
}
79+
};
80+
template <>
81+
struct formatter<std::filesystem::path, wchar_t>
82+
: formatter<basic_string_view<wchar_t>> {
83+
template <typename FormatContext>
84+
auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
85+
typename FormatContext::iterator {
86+
basic_memory_buffer<wchar_t> quoted;
87+
detail::write_escaped_path(quoted, p);
88+
return formatter<basic_string_view<wchar_t>>::format(
89+
basic_string_view<wchar_t>(quoted.data(), quoted.size()), ctx);
90+
}
91+
};
92+
#endif
6593
FMT_END_NAMESPACE
6694
#endif
6795

0 commit comments

Comments
 (0)