Search code examples
c++fmt

Where is the implementation for FMT_API auto vformat(string_view fmt, format_args args) -> std::string;?


I can see the declaration for vformat(string_view fmt, format_args args) in core.h.

FMT_API auto vformat(string_view fmt, format_args args) -> std::string;   //line number 3190

But I can't find the implementation for said funciton after I have carefully searched and read the project.

I only can see the declaration and implementation of fmt::v9::detail::vformat(const Locale& loc, basic_string_view<Char> format_str, basic_format_args<buffer_context<type_identity_t<Char>>> args) in format.h, but it not what I am looking for.

template <typename Locale, typename Char>
auto vformat(const Locale& loc, basic_string_view<Char> format_str,
             basic_format_args<buffer_context<type_identity_t<Char>>> args)
    -> std::basic_string<Char> {
  basic_memory_buffer<Char> buffer;
  detail::vformat_to(buffer, format_str, args, detail::locale_ref(loc));
  return {buffer.data(), buffer.size()};
}


Solution

  • It is implemented in format-inl.h

    FMT_FUNC std::string vformat(string_view fmt, format_args args) {
      // Don't optimize the "{}" case to keep the binary size small and because it
      // can be better optimized in fmt::format anyway.
      auto buffer = memory_buffer();
      detail::vformat_to(buffer, fmt, args);
      return to_string(buffer);
    }