use detail::write instead of re-implementing it
This commit is contained in:
parent
fd16204bf3
commit
104b3de77b
@ -330,40 +330,6 @@ template <typename T> struct printf_formatter {
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
template <typename, typename = void>
|
||||
struct has_container_append : std::false_type {};
|
||||
|
||||
template <typename OutputIt>
|
||||
struct has_container_append<
|
||||
OutputIt,
|
||||
void_t<decltype(
|
||||
get_container(std::declval<OutputIt>())
|
||||
.append(std::declval<
|
||||
const typename OutputIt::container_type::value_type*>(),
|
||||
std::declval<const typename OutputIt::container_type::
|
||||
value_type*>()))>> : std::true_type {};
|
||||
|
||||
template <typename OutputIt>
|
||||
enable_if_t<has_container_append<OutputIt>::value, OutputIt>
|
||||
container_aware_copy(const typename OutputIt::container_type::value_type* first,
|
||||
const typename OutputIt::container_type::value_type* last,
|
||||
OutputIt out) {
|
||||
detail::get_container(out).append(first, last);
|
||||
return out;
|
||||
}
|
||||
|
||||
static_assert(has_container_append<buffer_appender<char>>::value,
|
||||
"has_container_append doesn't work");
|
||||
|
||||
template <typename OutputIt, typename Char>
|
||||
enable_if_t<!has_container_append<OutputIt>::value, OutputIt>
|
||||
container_aware_copy(const Char* first, const Char* last, OutputIt out) {
|
||||
return std::copy(first, last, out);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
This template formats data and writes the output through an output iterator.
|
||||
*/
|
||||
@ -514,11 +480,11 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
|
||||
}
|
||||
char_type c = *it++;
|
||||
if (it != end && *it == c) {
|
||||
out = container_aware_copy(start, it, out);
|
||||
out = detail::write(out, basic_string_view<Char>(start, it - start));
|
||||
start = ++it;
|
||||
continue;
|
||||
}
|
||||
out = container_aware_copy(start, it - 1, out);
|
||||
out = detail::write(out, basic_string_view<Char>(start, it - 1 - start));
|
||||
|
||||
format_specs specs;
|
||||
specs.align = align::right;
|
||||
@ -630,7 +596,7 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
|
||||
// Format argument.
|
||||
out = visit_format_arg(ArgFormatter(out, specs, *this), arg);
|
||||
}
|
||||
return container_aware_copy(start, it, out);
|
||||
return detail::write(out, basic_string_view<Char>(start, it - start));
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user