FastFormat
The fastest, most robust C++ formatting library
Table of Contents
Introduction
FastFormat is an extremely fast, 100% type-safe, infinitely-extensible,
I18N/L10N-friendly C++ output/formatting library. Format strings use
replacement parameters of the form {0}, {1}, …; arguments are type-safe
at compile time; and output goes to any sink that accepts an array of
string slices (streams, FILE*, buffers, platform-specific destinations,
speech synthesisers, and more).
The library is released under a BSD-style licence. Source and issues live
at https://github.com/synesissoftware/FastFormat.
Developer Experience
Install STLSoft (1.11.9 or later) via CMake, then clone FastFormat and:
./prepare_cmake.sh --run-make # also use '--cmake-verbose-makefile' to see verbose output
./run_all_automated_tests.sh --no-make
Automated tests need xTests 0.29.0 or later. shwild is optional and enables richer xTests matches. Pass --disable-testing to prepare_cmake.sh when xTests is not installed. On Windows, scratch programs that include <unixem/unixem.h> need UNIXem 1.15.0 or later (see Dependencies).
A format statement names a sink, a format string whose replacement parameters are {0}, {1}, …, and the arguments. fastformat/ff.hpp is the application layer; fastformat/sinks/ostream.hpp writes those slices to std::ostream. The shortest program prints one line:
#include <fastformat/ff.hpp>
#include <fastformat/sinks/ostream.hpp>
#include <iostream>
int main()
{
fastformat::fmtln(std::cout, "Hello, {0}!", "World");
return 0;
}
find_package(FastFormat REQUIRED)
target_link_libraries(hello
PRIVATE
FastFormat::fastformat
)
Clone or a release archive, flags, and install: INSTALL.md. Generated API pages: ./generate_doxygen.sh. The longer walkthrough is examples/101/normal.
Installation
Obtain, configure, and install steps are in INSTALL.md. The consumer link line is in Developer Experience.
API documentation (Doxygen)
HTML API reference for the public headers may be generated locally:
./generate_doxygen.sh
Open _build/doxygen/html/index.html in a browser (or
<build-dir>/doxygen/html/index.html when SIS_CMAKE_BUILD_DIR is set).
Requires Doxygen on PATH.
Components
FastFormat is organised around a core formatting API, typed inserters,
output sinks, optional localised bundles, and helpers for format-defect
handling. The usual include is fastformat/ff.hpp (or
fastformat/fastformat.hpp), plus the sink header for the destination
you use.
Line badges mark the MAJOR.MINOR line that first shipped each component
in the public API. Items that pre-date 0.7 are labelled 0.7. The
0.9 badge is reserved for a future line and is unused below.
Core and application layer
| Header / API |
Role |
Since |
fastformat/fastformat.h |
Core types, version macros (FASTFORMAT_VER, FASTFORMAT_VER_RELSTATUS), C API entry points, initialisation |
|
fastformat_getVersion() |
Runtime packed version query |
|
fastformat_getParseCodeString[Length]() / fastformat_getReplacementCodeString[Length]() |
Human-readable strings for parse and replacement codes |
|
Ill-formed / mismatched handler model (ff_handler_response_t, ff_parse_action_t, ff_replacement_action_t, ff_*Handler_info_t setters) |
Explicit continue / next-handler responses and recovery actions (blank, literal, or slice) |
|
fastformat/fastformat.hpp |
C++ application layer: fmt, fmtln, write, writeln, flush |
|
fastformat/ff.hpp |
Convenience include that pulls in the application layer |
|
fastformat/exceptions.hpp |
Exception types; argument-count field is numArguments (was numberOfReplacements on 0.7) |
|
fastformat/init_codes.h |
Initialisation result codes |
|
fastformat/implicit_link.h |
Implicit-link helpers for selected toolchains |
|
The shortest program is in Developer Experience.
Inserters
Typed adapters under include/fastformat/inserters/
format values that are not already string-compatible. Common headers:
Sinks
Sinks under include/fastformat/sinks/ receive
the formatted slices. Common headers: