diff --git a/doc/api.rst b/doc/api.rst index 88e4f75f..f79e1688 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -187,14 +187,14 @@ Write API The write API provides classes for writing formatted data into character streams. It is usually faster than the `format API`_ but, as IOStreams, may result in larger compiled code size. The main writer class is -`~fmt::BasicMemoryWriter` which stores its output in a memory buffer and +`~fmt::basic_memory_writer` which stores its output in a memory buffer and provides direct access to it. It is possible to create custom writers that store output elsewhere by subclassing `~fmt::BasicWriter`. .. doxygenclass:: fmt::BasicWriter :members: -.. doxygenclass:: fmt::BasicMemoryWriter +.. doxygenclass:: fmt::basic_memory_writer :members: .. doxygenclass:: fmt::BasicArrayWriter @@ -220,8 +220,6 @@ Utilities .. doxygenfunction:: operator""_a(const char *, std::size_t) -.. doxygendefine:: FMT_CAPTURE - .. doxygenclass:: fmt::basic_format_args :members: @@ -230,7 +228,7 @@ Utilities .. doxygenclass:: fmt::basic_string_view :members: -.. doxygenclass:: fmt::Buffer +.. doxygenclass:: fmt::basic_memory_buffer :protected-members: :members: @@ -250,22 +248,29 @@ System errors Custom allocators ================= -The fmt library supports custom dynamic memory allocators. +The {fmt} library supports custom dynamic memory allocators. A custom allocator class can be specified as a template argument to -:class:`fmt::BasicMemoryWriter`:: +:class:`fmt::basic_memory_buffer`:: - typedef fmt::BasicMemoryWriter CustomMemoryWriter; + using custom_memory_buffer = + fmt::basic_memory_buffer; It is also possible to write a formatting function that uses a custom allocator:: - typedef std::basic_string, CustomAllocator> - CustomString; + using custom_string = + std::basic_string, custom_allocator>; - CustomString format(CustomAllocator alloc, fmt::CStringRef format_str, - fmt::ArgList args) { - CustomMemoryWriter writer(alloc); - writer.write(format_str, args); - return CustomString(writer.data(), writer.size(), alloc); + custom_string format(custom_allocator alloc, fmt::string_view format_str, + fmt::format_args args) { + custom_memory_buffer buf(alloc); + fmt::vformat_to(buf, format_str, args); + return custom_string(buf.data(), buf.size(), alloc); + } + + template + inline custom_string format(custom_allocator alloc, + fmt::string_view format_str, + const Args & ... args) { + return vformat(alloc, format_str, fmt::make_args(args...)); } - FMT_VARIADIC(CustomString, format, CustomAllocator, fmt::CStringRef) diff --git a/include/fmt/core.h b/include/fmt/core.h index ebcf7cfe..166447b1 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1114,11 +1114,11 @@ struct named_arg : named_arg_base { /** \rst - Returns a named argument for formatting functions. + Returns a named argument to be used in a formatting function. **Example**:: - fmt::print("Elapsed time: {s:.2f} seconds", arg("s", 1.23)); + fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23)); \endrst */ template diff --git a/include/fmt/format.h b/include/fmt/format.h index 94b1cfcb..32652a67 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -374,7 +374,7 @@ class locale_provider { /** \rst A dynamically growing memory buffer for trivially copyable/constructible types - with the first SIZE elements stored in the object itself. + with the first ``SIZE`` elements stored in the object itself. You can use one of the following typedefs for common character types: @@ -388,7 +388,7 @@ class locale_provider { **Example**:: - memory_buffer out; + fmt::memory_buffer out; format_to(out, "The answer is {}.", 42); This will write the following output to the ``out`` object: @@ -3487,7 +3487,7 @@ operator"" _format(const wchar_t *s, std::size_t) { return {s}; } **Example**:: using namespace fmt::literals; - print("Elapsed time: {s:.2f} seconds", "s"_a=1.23); + fmt::print("Elapsed time: {s:.2f} seconds", "s"_a=1.23); \endrst */ inline internal::udl_arg diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 4bc92253..9a189844 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -635,7 +635,7 @@ inline int vfprintf(std::ostream &os, string_view format_str, **Example**:: - fprintf(cerr, "Don't %s!", "panic"); + fmt::fprintf(cerr, "Don't %s!", "panic"); \endrst */ template