diff --git a/include/fmt/std.h b/include/fmt/std.h index d8093a9b..dc1e7832 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -15,14 +15,13 @@ # include # include # include -# include # include -# include +# include // std::reference_wrapper # include # include # include -# include -# include +# include // std::type_info +# include // std::make_index_sequence // Check FMT_CPLUSPLUS to suppress a bogus warning in MSVC. # if FMT_CPLUSPLUS >= 201703L @@ -132,16 +131,15 @@ template struct is_variant_like_ : std::false_type {}; template struct is_variant_like_> : std::true_type {}; -// formattable element check. -template class is_variant_formattable_ { - template +template class is_variant_formattable { + template static std::conjunction< - is_formattable, C>...> + is_formattable, Char>...> check(std::index_sequence); public: static constexpr const bool value = - decltype(check(variant_index_sequence{}))::value; + decltype(check(variant_index_sequence{}))::value; }; #endif // FMT_CPP_LIB_VARIANT @@ -152,7 +150,7 @@ template auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt { # ifdef FMT_HAS_ABI_CXA_DEMANGLE int status = 0; - std::size_t size = 0; + size_t size = 0; std::unique_ptr demangled_name_ptr( abi::__cxa_demangle(ti.name(), nullptr, &size, &status), &std::free); @@ -191,7 +189,7 @@ auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt { return detail::write_bytes(out, demangled_name_view); # elif FMT_MSC_VERSION const string_view demangled_name(ti.name()); - for (std::size_t i = 0; i < demangled_name.size(); ++i) { + for (size_t i = 0; i < demangled_name.size(); ++i) { auto sub = demangled_name; sub.remove_prefix(i); if (sub.starts_with("enum ")) { @@ -240,8 +238,31 @@ struct is_bit_reference_like> { } // namespace detail +template +auto ptr(const std::unique_ptr& p) -> const void* { + return p.get(); +} +template auto ptr(const std::shared_ptr& p) -> const void* { + return p.get(); +} + #if FMT_CPP_LIB_FILESYSTEM +class path : public std::filesystem::path { + public: + auto display_string() const -> std::string { + const std::filesystem::path& base = *this; + return fmt::format(FMT_STRING("{}"), base); + } + auto system_string() const -> std::string { return string(); } + + auto generic_display_string() const -> std::string { + const std::filesystem::path& base = *this; + return fmt::format(FMT_STRING("{:g}"), base); + } + auto generic_system_string() const -> std::string { return generic_string(); } +}; + template struct formatter { private: format_specs specs_; @@ -291,37 +312,20 @@ template struct formatter { } }; -class path : public std::filesystem::path { - public: - auto display_string() const -> std::string { - const std::filesystem::path& base = *this; - return fmt::format(FMT_STRING("{}"), base); - } - auto system_string() const -> std::string { return string(); } - - auto generic_display_string() const -> std::string { - const std::filesystem::path& base = *this; - return fmt::format(FMT_STRING("{:g}"), base); - } - auto generic_system_string() const -> std::string { return generic_string(); } -}; - #endif // FMT_CPP_LIB_FILESYSTEM -template +template struct formatter, Char> : nested_formatter, Char> { private: - // Functor because C++11 doesn't support generic lambdas. + // This is functor because C++11 doesn't support generic lambdas. struct writer { const std::bitset& bs; template FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt { - for (auto pos = N; pos > 0; --pos) { + for (auto pos = N; pos > 0; --pos) out = detail::write(out, bs[pos - 1] ? Char('1') : Char('0')); - } - return out; } }; @@ -433,11 +437,6 @@ template struct is_variant_like { static constexpr const bool value = detail::is_variant_like_::value; }; -template struct is_variant_formattable { - static constexpr const bool value = - detail::is_variant_formattable_::value; -}; - template struct formatter { FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { return ctx.begin(); @@ -451,10 +450,10 @@ template struct formatter { }; template -struct formatter< - Variant, Char, - std::enable_if_t, is_variant_formattable>>> { +struct formatter, + detail::is_variant_formattable>>> { FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { return ctx.begin(); } @@ -599,14 +598,6 @@ struct formatter -auto ptr(const std::unique_ptr& p) -> const void* { - return p.get(); -} -template auto ptr(const std::shared_ptr& p) -> const void* { - return p.get(); -} - template struct formatter, Char, enable_if_t::value>>