From 19c074e477c9f43374be3c3c0f7b0fca0def0e1a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 26 Mar 2023 08:40:12 -0700 Subject: [PATCH] Remove deprecated fallback formatter --- include/fmt/core.h | 44 ++++++++++-------------------------------- include/fmt/format.h | 13 ++----------- include/fmt/ostream.h | 45 ++----------------------------------------- include/fmt/ranges.h | 16 +++++---------- 4 files changed, 19 insertions(+), 99 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 9f93776a..e437186d 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1160,20 +1160,6 @@ auto get_iterator(buffer&, OutputIt out) -> OutputIt { return out; } -template -struct fallback_formatter { - fallback_formatter() = delete; -}; - -// Specifies if T has an enabled fallback_formatter specialization. -template -using has_fallback_formatter = -#ifdef FMT_DEPRECATED_OSTREAM - std::is_constructible>; -#else - std::false_type; -#endif - struct view {}; template struct named_arg : view { @@ -1332,10 +1318,7 @@ template class value { // have different extension points, e.g. `formatter` for `format` and // `printf_formatter` for `printf`. custom.format = format_custom_arg< - value_type, - conditional_t::value, - typename Context::template formatter_type, - fallback_formatter>>; + value_type, typename Context::template formatter_type>; } value(unformattable); value(unformattable_char); @@ -1493,8 +1476,7 @@ template struct arg_mapper { template > struct formattable : bool_constant() || - !std::is_const>::value || - has_fallback_formatter::value> {}; + !std::is_const>::value> {}; #if (FMT_MSC_VERSION != 0 && FMT_MSC_VERSION < 1910) || \ FMT_ICC_VERSION != 0 || defined(__NVCC__) @@ -1518,8 +1500,7 @@ template struct arg_mapper { !std::is_array::value && !std::is_pointer::value && !std::is_arithmetic>::value && - (has_formatter::value || - has_fallback_formatter::value))> + has_formatter::value)> FMT_CONSTEXPR FMT_INLINE auto map(T&& val) -> decltype(this->do_map(std::forward(val))) { return do_map(std::forward(val)); @@ -1770,9 +1751,9 @@ FMT_CONSTEXPR auto make_arg(T&& value) -> basic_format_arg { return arg; } -// The type template parameter is there to avoid an ODR violation when using -// a fallback formatter in one translation unit and an implicit conversion in -// another (not recommended). +// The DEPRECATED type template parameter is there to avoid an ODR violation +// when using a fallback formatter in one translation unit and an implicit +// conversion in another (not recommended). template FMT_CONSTEXPR FMT_INLINE auto make_arg(T&& val) -> value { @@ -1843,11 +1824,9 @@ using buffer_context = using format_context = buffer_context; template -using is_formattable = bool_constant< - !std::is_base_of>().map( - std::declval()))>::value && - !detail::has_fallback_formatter::value>; +using is_formattable = bool_constant>() + .map(std::declval()))>::value>; /** \rst @@ -2631,10 +2610,7 @@ FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx) mapped_type_constant::value != type::custom_type, decltype(arg_mapper().map(std::declval())), stripped_type>; - auto f = conditional_t::value, - formatter, - fallback_formatter>(); - return f.parse(ctx); + return formatter().parse(ctx); } // Checks char specs and returns true iff the presentation type is char-like. diff --git a/include/fmt/format.h b/include/fmt/format.h index 0ed59422..47eab794 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3891,12 +3891,8 @@ template enable_if_t::value == type::custom_type, OutputIt> { - using formatter_type = - conditional_t::value, - typename Context::template formatter_type, - fallback_formatter>; auto ctx = Context(out, {}, {}); - return formatter_type().format(value, ctx); + return typename Context::template formatter_type().format(value, ctx); } // An argument visitor that formats the argument and writes it via the output @@ -4382,12 +4378,7 @@ struct formatter, Char> { #else typename std::iterator_traits::value_type; #endif - using formatter_type = - conditional_t::value, - formatter, Char>, - detail::fallback_formatter>; - - formatter_type value_formatter_; + formatter, Char> value_formatter_; public: template diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 6a302b42..ab9a7d55 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -8,8 +8,8 @@ #ifndef FMT_OSTREAM_H_ #define FMT_OSTREAM_H_ -#include -#include +#include // std::filebuf + #if defined(_WIN32) && defined(__GLIBCXX__) # include # include @@ -21,42 +21,8 @@ FMT_BEGIN_NAMESPACE -template class basic_printf_context; - namespace detail { -// Checks if T has a user-defined operator<<. -template -class is_streamable { - private: - template - static auto test(int) - -> bool_constant&>() - << std::declval()) != 0>; - - template static auto test(...) -> std::false_type; - - using result = decltype(test(0)); - - public: - is_streamable() = default; - - static const bool value = result::value; -}; - -// Formatting of built-in types and arrays is intentionally disabled because -// it's handled by standard (non-ostream) formatters. -template -struct is_streamable< - T, Char, - enable_if_t< - std::is_arithmetic::value || std::is_array::value || - std::is_pointer::value || std::is_same::value || - std::is_convertible>::value || - std::is_same>::value || - (std::is_convertible::value && !std::is_enum::value)>> - : std::false_type {}; - // Generate a unique explicit instantion in every translation unit using a tag // type in an anonymous namespace. namespace { @@ -180,13 +146,6 @@ auto streamed(const T& value) -> detail::streamed_view { namespace detail { -// Formats an object of type T that has an overloaded ostream operator<<. -template -struct fallback_formatter::value>> - : basic_ostream_formatter { - using basic_ostream_formatter::format; -}; - inline void vprint_directly(std::ostream& os, string_view format_str, format_args args) { auto buffer = memory_buffer(); diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index c63b4f86..3dfb9500 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -404,12 +404,10 @@ template struct range_mapper { }; template -using range_formatter_type = conditional_t< - is_formattable::value, +using range_formatter_type = formatter>{}.map( std::declval()))>, - Char>, - fallback_formatter>; + Char>; template using maybe_const_range = @@ -419,9 +417,7 @@ using maybe_const_range = #if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1910 template struct is_formattable_delayed - : disjunction< - is_formattable>, Char>, - has_fallback_formatter>, Char>> {}; + : is_formattable>, Char> {}; #endif } // namespace detail @@ -431,10 +427,8 @@ struct range_formatter; template struct range_formatter< T, Char, - enable_if_t>, - disjunction, - detail::has_fallback_formatter>>::value>> { + enable_if_t>, + is_formattable>::value>> { private: detail::range_formatter_type underlying_; basic_string_view separator_ = detail::string_literal{};