From ae413ebf7a3dc0ba70bc0976a8cf12c6f4fb8200 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 1 Oct 2014 08:49:20 -0700 Subject: [PATCH] Add a section on custom allocators --- doc/index.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/index.rst b/doc/index.rst index 591dd59d..e87f2500 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -105,6 +105,28 @@ System Errors .. _formatstrings: +Custom allocators +----------------- + +The C++ Format library supports custom dynamic memory allocators. +A custom allocator class can be specified as a template argument to +:cpp:class:`fmt::BasicMemoryWriter`:: + + typedef fmt::BasicMemoryWriter CustomMemoryWriter; + +It is also possible to write a formatting function that uses a custom +allocator:: + + typedef std::basic_string, CustomAllocator> CustomString; + + CustomString format(CustomAllocator alloc, fmt::StringRef format_str, + fmt::ArgList args) { + CustomMemoryWriter writer(alloc); + writer.write(format_str, args); + return CustomString(writer.data(), writer.size(), alloc); + } + FMT_VARIADIC(CustomString, format, CustomAllocator, fmt::StringRef) + Format String Syntax --------------------