@@ -463,16 +463,16 @@ template <> inline void reset_color<wchar_t>(FILE* stream) FMT_NOEXCEPT {
463463}
464464
465465template <typename Char>
466- inline void reset_color (basic_memory_buffer <Char>& buffer) FMT_NOEXCEPT {
466+ inline void reset_color (buffer <Char>& buffer) FMT_NOEXCEPT {
467467 const char * begin = data::reset_color;
468468 const char * end = begin + sizeof (data::reset_color) - 1 ;
469469 buffer.append (begin, end);
470470}
471471
472472template <typename Char>
473- void vformat_to (basic_memory_buffer <Char>& buf, const text_style& ts,
473+ void vformat_to (buffer <Char>& buf, const text_style& ts,
474474 basic_string_view<Char> format_str,
475- basic_format_args<buffer_context<Char>> args) {
475+ basic_format_args<buffer_context<type_identity_t < Char> >> args) {
476476 bool has_style = false ;
477477 if (ts.has_emphasis ()) {
478478 has_style = true ;
@@ -496,28 +496,30 @@ void vformat_to(basic_memory_buffer<Char>& buf, const text_style& ts,
496496
497497template <typename S, typename Char = char_t <S>>
498498void vprint (std::FILE* f, const text_style& ts, const S& format,
499- basic_format_args<buffer_context<Char>> args) {
499+ basic_format_args<buffer_context<type_identity_t < Char> >> args) {
500500 basic_memory_buffer<Char> buf;
501501 detail::vformat_to (buf, ts, to_string_view (format), args);
502502 buf.push_back (Char (0 ));
503503 detail::fputs (buf.data (), f);
504504}
505505
506506/* *
507+ \rst
507508 Formats a string and prints it to the specified file stream using ANSI
508509 escape sequences to specify text formatting.
509- Example:
510+
511+ **Example**::
512+
510513 fmt::print(fmt::emphasis::bold | fg(fmt::color::red),
511514 "Elapsed time: {0:.2f} seconds", 1.23);
515+ \endrst
512516 */
513517template <typename S, typename ... Args,
514518 FMT_ENABLE_IF (detail::is_string<S>::value)>
515519void print(std::FILE* f, const text_style& ts, const S& format_str,
516520 const Args&... args) {
517- detail::check_format_string<Args...>(format_str);
518- using context = buffer_context<char_t <S>>;
519- format_arg_store<context, Args...> as{args...};
520- vprint (f, ts, format_str, basic_format_args<context>(as));
521+ vprint (f, ts, format_str,
522+ fmt::make_args_checked<Args...>(format_str, args...));
521523}
522524
523525/* *
@@ -558,7 +560,42 @@ template <typename S, typename... Args, typename Char = char_t<S>>
558560inline std::basic_string<Char> format (const text_style& ts, const S& format_str,
559561 const Args&... args) {
560562 return vformat (ts, to_string_view (format_str),
561- detail::make_args_checked<Args...>(format_str, args...));
563+ fmt::make_args_checked<Args...>(format_str, args...));
564+ }
565+
566+ /* *
567+ Formats a string with the given text_style and writes the output to ``out``.
568+ */
569+ template <typename OutputIt, typename Char,
570+ FMT_ENABLE_IF (detail::is_output_iterator<OutputIt, Char>::value)>
571+ OutputIt vformat_to(
572+ OutputIt out, const text_style& ts, basic_string_view<Char> format_str,
573+ basic_format_args<buffer_context<type_identity_t <Char>>> args) {
574+ decltype (detail::get_buffer<Char>(out)) buf (detail::get_buffer_init (out));
575+ detail::vformat_to (buf, ts, format_str, args);
576+ return detail::get_iterator (buf);
577+ }
578+
579+ /* *
580+ \rst
581+ Formats arguments with the given text_style, writes the result to the output
582+ iterator ``out`` and returns the iterator past the end of the output range.
583+
584+ **Example**::
585+
586+ std::vector<char> out;
587+ fmt::format_to(std::back_inserter(out),
588+ fmt::emphasis::bold | fg(fmt::color::red), "{}", 42);
589+ \endrst
590+ */
591+ template <typename OutputIt, typename S, typename ... Args,
592+ bool enable = detail::is_output_iterator<OutputIt, char_t <S>>::value&&
593+ detail::is_string<S>::value>
594+ inline auto format_to (OutputIt out, const text_style& ts, const S& format_str,
595+ Args&&... args) ->
596+ typename std::enable_if<enable, OutputIt>::type {
597+ return vformat_to (out, ts, to_string_view (format_str),
598+ fmt::make_args_checked<Args...>(format_str, args...));
562599}
563600
564601FMT_END_NAMESPACE
0 commit comments