aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorVictor Zverovich <viz@fb.com>2020-07-20 07:56:20 -0700
committerVictor Zverovich <viz@fb.com>2020-07-20 07:56:20 -0700
commitc228bfe88233ba6ed67d0febc7a05b0300155978 (patch)
tree5c4995561d10001634c9f8cddd23450e4d7ef64f /doc
parent38ce19f738c01afafc41626c37bc307982c6b3e7 (diff)
downloadfmtlib-c228bfe88233ba6ed67d0febc7a05b0300155978.tar.gz
Improve docs
Diffstat (limited to 'doc')
-rw-r--r--doc/api.rst27
1 files changed, 27 insertions, 0 deletions
diff --git a/doc/api.rst b/doc/api.rst
index 28270144..157875dc 100644
--- a/doc/api.rst
+++ b/doc/api.rst
@@ -66,6 +66,33 @@ Named arguments are not supported in compile-time checks at the moment.
Argument Lists
--------------
+You can create your own formatting function with compile-time checks and small
+binary footprint, for example (https://godbolt.org/z/oba4Mc):
+
+.. code:: c++
+
+ #include <fmt/format.h>
+
+ void vlog(const char* file, int line, fmt::string_view format,
+ fmt::format_args args) {
+ fmt::print("{}: {}: ", file, line);
+ fmt::vprint(format, args);
+ }
+
+ template <typename S, typename... Args>
+ void log(const char* file, int line, const S& format, Args&&... args) {
+ vlog(file, line, format,
+ fmt::make_args_checked<Args...>(format, args...));
+ }
+
+ #define MY_LOG(format, ...) \
+ log(__FILE__, __LINE__, FMT_STRING(format), __VA_ARGS__)
+
+ MY_LOG("invalid squishiness: {}", 42);
+
+Note that ``vlog`` is not parameterized on argument types which improves compile
+times and reduces binary code size compared to a fully parameterized version.
+
.. doxygenfunction:: fmt::make_format_args(const Args&...)
.. doxygenfunction:: fmt::make_args_checked(const S&, const remove_reference_t<Args>&...)