mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 18:57:34 +02:00
Improve buffer extraction
This commit is contained in:
@ -594,7 +594,7 @@ template <typename OutputIt, typename Char,
|
|||||||
OutputIt vformat_to(
|
OutputIt vformat_to(
|
||||||
OutputIt out, const text_style& ts, basic_string_view<Char> format_str,
|
OutputIt out, const text_style& ts, basic_string_view<Char> format_str,
|
||||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||||
decltype(detail::get_buffer<Char>(out)) buf(detail::get_buffer_init(out));
|
detail::get_buffer_t<OutputIt, Char> buf(detail::get_buffer(out));
|
||||||
detail::vformat_to(buf, ts, format_str, args);
|
detail::vformat_to(buf, ts, format_str, args);
|
||||||
return detail::get_iterator(buf);
|
return detail::get_iterator(buf);
|
||||||
}
|
}
|
||||||
|
@ -924,11 +924,12 @@ using buffer_appender = conditional_t<std::is_same<T, char>::value, appender,
|
|||||||
std::back_insert_iterator<buffer<T>>>;
|
std::back_insert_iterator<buffer<T>>>;
|
||||||
|
|
||||||
// Maps an output iterator to a buffer.
|
// Maps an output iterator to a buffer.
|
||||||
template <typename T, typename OutputIt>
|
template <typename OutputIt, typename T>
|
||||||
auto get_buffer(OutputIt) -> iterator_buffer<OutputIt, T>;
|
using get_buffer_t =
|
||||||
template <typename T> auto get_buffer(buffer_appender<T>) -> buffer<T>&;
|
conditional_t<std::is_same<OutputIt, buffer_appender<T>>::value, buffer<T>&,
|
||||||
|
iterator_buffer<OutputIt, T>>;
|
||||||
|
|
||||||
template <typename OutputIt> auto get_buffer_init(OutputIt out) -> OutputIt {
|
template <typename OutputIt> auto get_buffer(OutputIt out) -> OutputIt {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1339,7 +1340,7 @@ FMT_END_DETAIL_NAMESPACE
|
|||||||
class appender : public std::back_insert_iterator<detail::buffer<char>> {
|
class appender : public std::back_insert_iterator<detail::buffer<char>> {
|
||||||
using base = std::back_insert_iterator<detail::buffer<char>>;
|
using base = std::back_insert_iterator<detail::buffer<char>>;
|
||||||
|
|
||||||
friend auto get_buffer_init(appender out) -> detail::buffer<char>& {
|
friend auto get_buffer(appender out) -> detail::buffer<char>& {
|
||||||
return detail::get_container(out);
|
return detail::get_container(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2847,8 +2848,8 @@ FMT_INLINE auto format(format_string<T...> fmt, T&&... args) -> std::string {
|
|||||||
template <typename OutputIt,
|
template <typename OutputIt,
|
||||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
|
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
|
||||||
auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
|
auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
|
||||||
using detail::get_buffer_init;
|
using detail::get_buffer;
|
||||||
decltype(detail::get_buffer<char>(out)) buf(get_buffer_init(out));
|
detail::get_buffer_t<OutputIt, char> buf(get_buffer(out));
|
||||||
detail::vformat_to(buf, string_view(fmt), args);
|
detail::vformat_to(buf, string_view(fmt), args);
|
||||||
return detail::get_iterator(buf);
|
return detail::get_iterator(buf);
|
||||||
}
|
}
|
||||||
|
@ -2695,7 +2695,7 @@ template <typename OutputIt, typename S, typename Char = char_t<S>,
|
|||||||
auto vformat_to(OutputIt out, const S& format_str,
|
auto vformat_to(OutputIt out, const S& format_str,
|
||||||
basic_format_args<buffer_context<type_identity_t<Char>>> args)
|
basic_format_args<buffer_context<type_identity_t<Char>>> args)
|
||||||
-> OutputIt {
|
-> OutputIt {
|
||||||
decltype(detail::get_buffer<Char>(out)) buf(detail::get_buffer_init(out));
|
detail::get_buffer_t<OutputIt, Char> buf(detail::get_buffer(out));
|
||||||
detail::vformat_to(buf, to_string_view(format_str), args);
|
detail::vformat_to(buf, to_string_view(format_str), args);
|
||||||
return detail::get_iterator(buf);
|
return detail::get_iterator(buf);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ template <typename S, typename OutputIt, typename... Args,
|
|||||||
inline OutputIt vformat_to(
|
inline OutputIt vformat_to(
|
||||||
OutputIt out, const std::locale& loc, const S& format_str,
|
OutputIt out, const std::locale& loc, const S& format_str,
|
||||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||||
decltype(detail::get_buffer<Char>(out)) buf(detail::get_buffer_init(out));
|
detail::get_buffer_t<OutputIt, Char> buf(detail::get_buffer(out));
|
||||||
vformat_to(buf, to_string_view(format_str), args, detail::locale_ref(loc));
|
vformat_to(buf, to_string_view(format_str), args, detail::locale_ref(loc));
|
||||||
return detail::get_iterator(buf);
|
return detail::get_iterator(buf);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user