Repository: fmtlib/fmt
File: include/fmt/base.h (C/C++)

Code before:

  **Example**::

    // Check format string at runtime instead of compile-time.
    fmt::print(fmt::runtime("{:d}"), "I am not a number");
  \endrst
 */
inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; }
#endif

/** Formats a string and writes the output to ``out``. */
template <typename OutputIt,
          FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
                                                   char>::value)>
auto vformat_to(OutputIt&& out, string_view fmt, format_args args)
    -> remove_cvref_t<OutputIt> {
  auto&& buf = detail::get_buffer<char>(out);
  detail::vformat_to(buf, fmt, args, {});
  return detail::get_iterator(buf, out);
}

template <typename OutputIt, typename OutputSen = OutputIt>
struct format_to_result {
  /** Iterator past the end of the last write. */
  OutputIt out;
  /** Iterator to the end of the output range. */
  OutputSen out_last;

  FMT_CONSTEXPR operator OutputIt&() & noexcept { return out; }
  FMT_CONSTEXPR operator const OutputIt&() const& noexcept { return out; }
  FMT_CONSTEXPR operator OutputIt&&() && noexcept {
    return static_cast<OutputIt&&>(out);
  }
};

/** Formats a string and writes the output to ``out``. */
template <size_t Size>
auto vformat_to(char (&out)[Size], string_view fmt, format_args args)
    -> format_to_result<char*> {
  using traits = detail::fixed_buffer_traits;
  auto buf = detail::iterator_buffer<char*, char, traits>(out, Size);
  detail::vformat_to(buf, fmt, args, {});
  return {out + buf.count(), out + Size};
}

/**
 \rst
 Formats ``args`` according to specifications in ``fmt``, writes the result to
 the output iterator ``out`` and returns the iterator past the end of the output
 range. `format_to` does not append a terminating null character.


Review comment (suggestion):
It seems to be a sentinel so let's rephrase to something like:

```c++
/** Sentinel indicating the end of the output range. */
```

Code after:

  **Example**::

    // Check format string at runtime instead of compile-time.
    fmt::print(fmt::runtime("{:d}"), "I am not a number");
  \endrst
 */
inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; }
#endif

/** Formats a string and writes the output to ``out``. */
template <typename OutputIt,
          FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
                                                   char>::value)>
auto vformat_to(OutputIt&& out, string_view fmt, format_args args)
    -> remove_cvref_t<OutputIt> {
  auto&& buf = detail::get_buffer<char>(out);
  detail::vformat_to(buf, fmt, args, {});
  return detail::get_iterator(buf, out);
}

/**
 \rst
 Formats ``args`` according to specifications in ``fmt``, writes the result to
 the output iterator ``out`` and returns the iterator past the end of the output
 range. `format_to` does not append a terminating null character.

 **Example**::

   auto out = std::vector<char>();
   fmt::format_to(std::back_inserter(out), "{}", 42);
 \endrst
 */
template <typename OutputIt, typename... T,
          FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
                                                   char>::value)>
FMT_INLINE auto format_to(OutputIt&& out, format_string<T...> fmt, T&&... args)
    -> remove_cvref_t<OutputIt> {
  return vformat_to(FMT_FWD(out), fmt, fmt::make_format_args(args...));
}

template <typename OutputIt> struct format_to_n_result {
  /** Iterator past the end of the output range. */
  OutputIt out;
  /** Total (not truncated) output size. */
  size_t size;
};

template <typename OutputIt, typename... T,
          FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args)