Skip to content

Commit 8101036

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 09f52a0 commit 8101036

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
@@ -57,6 +57,7 @@ inline void write_escaped_path<std::filesystem::path::value_type>(
5757

5858
} // namespace detail
5959

60+
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920
6061
template <typename Char>
6162
struct formatter<std::filesystem::path, Char>
6263
: formatter<basic_string_view<Char>> {
@@ -69,6 +70,33 @@ struct formatter<std::filesystem::path, Char>
6970
basic_string_view<Char>(quoted.data(), quoted.size()), ctx);
7071
}
7172
};
73+
#else
74+
// Workaround for MSVC 2017 and earlier.
75+
template <>
76+
struct formatter<std::filesystem::path, char>
77+
: formatter<basic_string_view<char>> {
78+
template <typename FormatContext>
79+
auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
80+
typename FormatContext::iterator {
81+
basic_memory_buffer<char> quoted;
82+
detail::write_escaped_path(quoted, p);
83+
return formatter<basic_string_view<char>>::format(
84+
basic_string_view<char>(quoted.data(), quoted.size()), ctx);
85+
}
86+
};
87+
template <>
88+
struct formatter<std::filesystem::path, wchar_t>
89+
: formatter<basic_string_view<wchar_t>> {
90+
template <typename FormatContext>
91+
auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
92+
typename FormatContext::iterator {
93+
basic_memory_buffer<wchar_t> quoted;
94+
detail::write_escaped_path(quoted, p);
95+
return formatter<basic_string_view<wchar_t>>::format(
96+
basic_string_view<wchar_t>(quoted.data(), quoted.size()), ctx);
97+
}
98+
};
99+
#endif
72100
FMT_END_NAMESPACE
73101
#endif
74102

0 commit comments

Comments
 (0)