Fix path formatter

This commit is contained in:
Victor Zverovich 2022-05-17 14:23:56 -07:00
parent f0903ad9df
commit 9730fb0156
2 changed files with 9 additions and 7 deletions

View File

@ -8,22 +8,23 @@
#ifndef FMT_STD_H_ #ifndef FMT_STD_H_
#define FMT_STD_H_ #define FMT_STD_H_
#include <version> #include "format.h"
#if FMT_HAS_INCLUDE(<version>)
# include <version>
#endif
#ifdef __cpp_lib_filesystem #ifdef __cpp_lib_filesystem
# include <filesystem> # include <filesystem>
namespace fmt { template <>
struct fmt::formatter<std::filesystem::path> : formatter<string_view> {
template <> struct formatter<std::filesystem::path> : formatter<string_view> {
template <typename FormatContext> template <typename FormatContext>
auto format(const path& p, FormatContext& ctx) const -> auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
typename FormatContext::iterator { typename FormatContext::iterator {
return formatter<string_view>::format(p.string(), ctx); return formatter<string_view>::format(p.string(), ctx);
} }
}; };
} // namespace fmt
#endif #endif
#endif // FMT_STD_H_ #endif // FMT_STD_H_

View File

@ -77,6 +77,7 @@ endif()
add_fmt_test(printf-test) add_fmt_test(printf-test)
add_fmt_test(ranges-test ranges-odr-test.cc) add_fmt_test(ranges-test ranges-odr-test.cc)
add_fmt_test(scan-test) add_fmt_test(scan-test)
add_fmt_test(std-test)
add_fmt_test(unicode-test HEADER_ONLY) add_fmt_test(unicode-test HEADER_ONLY)
if (MSVC) if (MSVC)
target_compile_options(unicode-test PRIVATE /utf-8) target_compile_options(unicode-test PRIVATE /utf-8)