Simplify ostream opt-in API

This commit is contained in:
Victor Zverovich
2022-02-04 18:33:55 -08:00
parent a5a7e3a261
commit 17b362f78c
3 changed files with 23 additions and 20 deletions

View File

@@ -78,14 +78,12 @@ void format_value(buffer<Char>& buf, const T& value,
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
buf.try_resize(buf.size());
}
} // namespace detail
// Formats an object of type T that has an overloaded ostream operator<<.
template <typename T, typename Char>
struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
: private formatter<basic_string_view<Char>, Char> {
using formatter<basic_string_view<Char>, Char>::parse;
template <typename OutputIt>
template <typename Char>
struct basic_ostream_formatter : formatter<basic_string_view<Char>, Char> {
template <typename T, typename OutputIt>
auto format(const T& value, basic_format_context<OutputIt, Char>& ctx) const
-> OutputIt {
auto buffer = basic_memory_buffer<Char>();
@@ -93,7 +91,17 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
return formatter<basic_string_view<Char>, Char>::format(
{buffer.data(), buffer.size()}, ctx);
}
};
using ostream_formatter = basic_ostream_formatter<char>;
namespace detail {
// Formats an object of type T that has an overloaded ostream operator<<.
template <typename T, typename Char>
struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
: basic_ostream_formatter<Char> {
using basic_ostream_formatter<Char>::format;
// DEPRECATED!
template <typename OutputIt>
auto format(const T& value, basic_printf_context<OutputIt, Char>& ctx) const
@@ -105,9 +113,6 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
};
} // namespace detail
template <typename T, typename Char = char>
using ostream_formatter = detail::fallback_formatter<T, Char>;
FMT_MODULE_EXPORT
template <typename Char>
void vprint(std::basic_ostream<Char>& os, basic_string_view<Char> format_str,