mirror of
https://github.com/shadps4-emu/ext-fmt.git
synced 2024-11-23 09:49:42 +00:00
Simplify buffer extraction
This commit is contained in:
parent
2617384d8e
commit
1c83a49be9
@ -594,7 +594,7 @@ template <typename OutputIt, typename Char,
|
||||
OutputIt vformat_to(
|
||||
OutputIt out, const text_style& ts, basic_string_view<Char> format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||
detail::get_buffer_t<OutputIt, Char> buf(detail::get_buffer(out));
|
||||
auto&& buf = detail::get_buffer<Char>(out);
|
||||
detail::vformat_to(buf, ts, format_str, args);
|
||||
return detail::get_iterator(buf);
|
||||
}
|
||||
|
@ -763,6 +763,7 @@ template <typename T> class buffer {
|
||||
|
||||
buffer(const buffer&) = delete;
|
||||
void operator=(const buffer&) = delete;
|
||||
buffer(buffer&&) = default;
|
||||
|
||||
auto begin() FMT_NOEXCEPT -> T* { return ptr_; }
|
||||
auto end() FMT_NOEXCEPT -> T* { return ptr_ + size_; }
|
||||
@ -924,13 +925,9 @@ using buffer_appender = conditional_t<std::is_same<T, char>::value, appender,
|
||||
std::back_insert_iterator<buffer<T>>>;
|
||||
|
||||
// Maps an output iterator to a buffer.
|
||||
template <typename OutputIt, typename T>
|
||||
using get_buffer_t =
|
||||
conditional_t<std::is_same<OutputIt, buffer_appender<T>>::value, buffer<T>&,
|
||||
iterator_buffer<OutputIt, T>>;
|
||||
|
||||
template <typename OutputIt> auto get_buffer(OutputIt out) -> OutputIt {
|
||||
return out;
|
||||
template <typename T, typename OutputIt>
|
||||
auto get_buffer(OutputIt out) -> iterator_buffer<OutputIt, T> {
|
||||
return iterator_buffer<OutputIt, T>(out);
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
@ -1340,6 +1337,7 @@ FMT_END_DETAIL_NAMESPACE
|
||||
class appender : public std::back_insert_iterator<detail::buffer<char>> {
|
||||
using base = std::back_insert_iterator<detail::buffer<char>>;
|
||||
|
||||
template <typename T>
|
||||
friend auto get_buffer(appender out) -> detail::buffer<char>& {
|
||||
return detail::get_container(out);
|
||||
}
|
||||
@ -2849,7 +2847,7 @@ template <typename OutputIt,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
|
||||
auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
|
||||
using detail::get_buffer;
|
||||
detail::get_buffer_t<OutputIt, char> buf(get_buffer(out));
|
||||
auto&& buf = get_buffer<char>(out);
|
||||
detail::vformat_to(buf, string_view(fmt), args);
|
||||
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,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args)
|
||||
-> OutputIt {
|
||||
detail::get_buffer_t<OutputIt, Char> buf(detail::get_buffer(out));
|
||||
auto&& buf = detail::get_buffer<Char>(out);
|
||||
detail::vformat_to(buf, to_string_view(format_str), args);
|
||||
return detail::get_iterator(buf);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ template <typename S, typename OutputIt, typename... Args,
|
||||
inline OutputIt vformat_to(
|
||||
OutputIt out, const std::locale& loc, const S& format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||
detail::get_buffer_t<OutputIt, Char> buf(detail::get_buffer(out));
|
||||
auto&& buf = detail::get_buffer<Char>(out);
|
||||
vformat_to(buf, to_string_view(format_str), args, detail::locale_ref(loc));
|
||||
return detail::get_iterator(buf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user