Update docs

This commit is contained in:
Victor Zverovich
2018-03-04 09:55:17 -08:00
parent 86a9bc8291
commit 4023291759
4 changed files with 27 additions and 22 deletions

View File

@ -187,14 +187,14 @@ Write API
The write API provides classes for writing formatted data into character The write API provides classes for writing formatted data into character
streams. It is usually faster than the `format API`_ but, as IOStreams, streams. It is usually faster than the `format API`_ but, as IOStreams,
may result in larger compiled code size. The main writer class is 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 provides direct access to it. It is possible to create custom writers that
store output elsewhere by subclassing `~fmt::BasicWriter`. store output elsewhere by subclassing `~fmt::BasicWriter`.
.. doxygenclass:: fmt::BasicWriter .. doxygenclass:: fmt::BasicWriter
:members: :members:
.. doxygenclass:: fmt::BasicMemoryWriter .. doxygenclass:: fmt::basic_memory_writer
:members: :members:
.. doxygenclass:: fmt::BasicArrayWriter .. doxygenclass:: fmt::BasicArrayWriter
@ -220,8 +220,6 @@ Utilities
.. doxygenfunction:: operator""_a(const char *, std::size_t) .. doxygenfunction:: operator""_a(const char *, std::size_t)
.. doxygendefine:: FMT_CAPTURE
.. doxygenclass:: fmt::basic_format_args .. doxygenclass:: fmt::basic_format_args
:members: :members:
@ -230,7 +228,7 @@ Utilities
.. doxygenclass:: fmt::basic_string_view .. doxygenclass:: fmt::basic_string_view
:members: :members:
.. doxygenclass:: fmt::Buffer .. doxygenclass:: fmt::basic_memory_buffer
:protected-members: :protected-members:
:members: :members:
@ -250,22 +248,29 @@ System errors
Custom allocators 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 A custom allocator class can be specified as a template argument to
:class:`fmt::BasicMemoryWriter`:: :class:`fmt::basic_memory_buffer`::
typedef fmt::BasicMemoryWriter<char, CustomAllocator> CustomMemoryWriter; using custom_memory_buffer =
fmt::basic_memory_buffer<char, custom_allocator>;
It is also possible to write a formatting function that uses a custom It is also possible to write a formatting function that uses a custom
allocator:: allocator::
typedef std::basic_string<char, std::char_traits<char>, CustomAllocator> using custom_string =
CustomString; std::basic_string<char, std::char_traits<char>, custom_allocator>;
CustomString format(CustomAllocator alloc, fmt::CStringRef format_str, custom_string format(custom_allocator alloc, fmt::string_view format_str,
fmt::ArgList args) { fmt::format_args args) {
CustomMemoryWriter writer(alloc); custom_memory_buffer buf(alloc);
writer.write(format_str, args); fmt::vformat_to(buf, format_str, args);
return CustomString(writer.data(), writer.size(), alloc); return custom_string(buf.data(), buf.size(), alloc);
}
template <typename ...Args>
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)

View File

@ -1114,11 +1114,11 @@ struct named_arg : named_arg_base<Char> {
/** /**
\rst \rst
Returns a named argument for formatting functions. Returns a named argument to be used in a formatting function.
**Example**:: **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 \endrst
*/ */
template <typename T> template <typename T>

View File

@ -374,7 +374,7 @@ class locale_provider {
/** /**
\rst \rst
A dynamically growing memory buffer for trivially copyable/constructible types 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: You can use one of the following typedefs for common character types:
@ -388,7 +388,7 @@ class locale_provider {
**Example**:: **Example**::
memory_buffer out; fmt::memory_buffer out;
format_to(out, "The answer is {}.", 42); format_to(out, "The answer is {}.", 42);
This will write the following output to the ``out`` object: 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**:: **Example**::
using namespace fmt::literals; 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 \endrst
*/ */
inline internal::udl_arg<char> inline internal::udl_arg<char>

View File

@ -635,7 +635,7 @@ inline int vfprintf(std::ostream &os, string_view format_str,
**Example**:: **Example**::
fprintf(cerr, "Don't %s!", "panic"); fmt::fprintf(cerr, "Don't %s!", "panic");
\endrst \endrst
*/ */
template <typename... Args> template <typename... Args>