Skip to content

Commit

Permalink
fmtlib#2954: As workaround for older MSVC compilers split formatter<s…
Browse files Browse the repository at this point in the history
…td::filesystem::path> partial template specialization into two explicit specialization.
  • Loading branch information
Dani-Hub committed Jul 2, 2022
1 parent 4ccada9 commit 9c53225
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ inline void write_escaped_path<std::filesystem::path::value_type>(

} // namespace detail

#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920
template <typename Char>
struct formatter<std::filesystem::path, Char>
: formatter<basic_string_view<Char>> {
Expand All @@ -62,6 +63,33 @@ struct formatter<std::filesystem::path, Char>
basic_string_view<Char>(quoted.data(), quoted.size()), ctx);
}
};
#else
// Workaround for MSVC 2017 and earlier.
template <>
struct formatter<std::filesystem::path, char>
: formatter<basic_string_view<char>> {
template <typename FormatContext>
auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
typename FormatContext::iterator {
basic_memory_buffer<char> quoted;
detail::write_escaped_path(quoted, p);
return formatter<basic_string_view<char>>::format(
basic_string_view<char>(quoted.data(), quoted.size()), ctx);
}
};
template <>
struct formatter<std::filesystem::path, wchar_t>
: formatter<basic_string_view<wchar_t>> {
template <typename FormatContext>
auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
typename FormatContext::iterator {
basic_memory_buffer<wchar_t> quoted;
detail::write_escaped_path(quoted, p);
return formatter<basic_string_view<wchar_t>>::format(
basic_string_view<wchar_t>(quoted.data(), quoted.size()), ctx);
}
};
#endif
FMT_END_NAMESPACE
#endif

Expand Down

0 comments on commit 9c53225

Please sign in to comment.