@@ -113,7 +113,8 @@ binary footprint, for example (https://godbolt.org/z/oba4Mc):
113
113
114
114
template <typename S, typename... Args>
115
115
void log(const char* file, int line, const S& format, Args&&... args) {
116
- vlog(file, line, format, fmt::make_format_args(args...));
116
+ vlog(file, line, format,
117
+ fmt::make_args_checked<Args...>(format, args...));
117
118
}
118
119
119
120
#define MY_LOG(format, ...) \
@@ -124,6 +125,8 @@ binary footprint, for example (https://godbolt.org/z/oba4Mc):
124
125
Note that ``vlog `` is not parameterized on argument types which improves compile
125
126
times and reduces binary code size compared to a fully parameterized version.
126
127
128
+ .. doxygenfunction :: fmt::make_args_checked(const S&, const remove_reference_t<Args>&...)
129
+
127
130
.. doxygenfunction :: fmt::make_format_args(const Args&...)
128
131
129
132
.. doxygenclass :: fmt::format_arg_store
@@ -179,11 +182,6 @@ functions and locale support.
179
182
Formatting User-defined Types
180
183
-----------------------------
181
184
182
- The {fmt} library provides formatters for many standard C++ types.
183
- See :ref: `fmt/ranges.h <ranges-api >` for ranges and tuples including standard
184
- containers such as ``std::vector `` and :ref: `fmt/chrono.h <chrono-api >` for date
185
- and time formatting.
186
-
187
185
To make a user-defined type formattable, specialize the ``formatter<T> `` struct
188
186
template and implement ``parse `` and ``format `` methods::
189
187
@@ -224,7 +222,7 @@ template and implement ``parse`` and ``format`` methods::
224
222
// Formats the point p using the parsed format specification (presentation)
225
223
// stored in this formatter.
226
224
template <typename FormatContext>
227
- auto format(const point& p, FormatContext& ctx) const -> decltype(ctx.out()) {
225
+ auto format(const point& p, FormatContext& ctx) -> decltype(ctx.out()) {
228
226
// ctx.out() is an output iterator to write to.
229
227
return presentation == 'f'
230
228
? format_to(ctx.out(), "({:.1f}, {:.1f})", p.x, p.y)
@@ -246,7 +244,7 @@ example::
246
244
template <> struct fmt::formatter<color>: formatter<string_view> {
247
245
// parse is inherited from formatter<string_view>.
248
246
template <typename FormatContext>
249
- auto format(color c, FormatContext& ctx) const {
247
+ auto format(color c, FormatContext& ctx) {
250
248
string_view name = "unknown";
251
249
switch (c) {
252
250
case color::red: name = "red"; break;
@@ -284,7 +282,7 @@ You can also write a formatter for a hierarchy of classes::
284
282
struct fmt::formatter<T, std::enable_if_t<std::is_base_of<A, T>::value, char>> :
285
283
fmt::formatter<std::string> {
286
284
template <typename FormatCtx>
287
- auto format(const A& a, FormatCtx& ctx) const {
285
+ auto format(const A& a, FormatCtx& ctx) {
288
286
return fmt::formatter<std::string>::format(a.name(), ctx);
289
287
}
290
288
};
@@ -309,7 +307,7 @@ The following user-defined literals are defined in ``fmt/format.h``.
309
307
310
308
.. doxygenfunction :: operator""_format(const char *s, size_t n) -> detail::udl_formatter<char>
311
309
312
- .. doxygenfunction :: operator""_a()
310
+ .. doxygenfunction :: operator""_a(const char *s, size_t) -> detail::udl_arg<char>
313
311
314
312
Utilities
315
313
---------
@@ -318,8 +316,6 @@ Utilities
318
316
.. doxygenfunction :: fmt::ptr(const std::unique_ptr<T> &p) -> const void*
319
317
.. doxygenfunction :: fmt::ptr(const std::shared_ptr<T> &p) -> const void*
320
318
321
- .. doxygenfunction :: fmt::underlying(Enum e) -> typename std::underlying_type<Enum>::type
322
-
323
319
.. doxygenfunction :: fmt::to_string(const T &value) -> std::string
324
320
325
321
.. doxygenfunction :: fmt::to_string_view(const Char *s) -> basic_string_view<Char>
@@ -450,19 +446,16 @@ The format syntax is described in :ref:`chrono-specs`.
450
446
Format string compilation
451
447
=========================
452
448
453
- ``fmt/compile.h `` provides format string compilation enabled via the
454
- ``FMT_COMPILE `` macro or the ``_cf `` user-defined literal. Format strings
455
- marked with ``FMT_COMPILE `` or ``_cf `` are parsed, checked and converted into
456
- efficient formatting code at compile-time. This supports arguments of built-in
457
- and string types as well as user-defined types with ``constexpr `` ``parse ``
458
- functions in their ``formatter `` specializations. Format string compilation can
459
- generate more binary code compared to the default API and is only recommended in
460
- places where formatting is a performance bottleneck.
449
+ ``fmt/compile.h `` provides format string compilation support when using
450
+ ``FMT_COMPILE ``. Format strings are parsed, checked and converted into efficient
451
+ formatting code at compile-time. This supports arguments of built-in and string
452
+ types as well as user-defined types with ``constexpr `` ``parse `` functions in
453
+ their ``formatter `` specializations. Format string compilation can generate more
454
+ binary code compared to the default API and is only recommended in places where
455
+ formatting is a performance bottleneck.
461
456
462
457
.. doxygendefine :: FMT_COMPILE
463
458
464
- .. doxygenfunction :: operator""_cf()
465
-
466
459
.. _color-api :
467
460
468
461
Terminal color and text style
@@ -476,8 +469,6 @@ Terminal color and text style
476
469
477
470
.. doxygenfunction :: bg(detail::color_type)
478
471
479
- .. doxygenfunction :: styled(const T& value, text_style ts)
480
-
481
472
.. _os-api :
482
473
483
474
System APIs
@@ -495,9 +486,7 @@ System APIs
495
486
========================
496
487
497
488
``fmt/ostream.h `` provides ``std::ostream `` support including formatting of
498
- user-defined types that have an overloaded insertion operator (``operator<< ``).
499
- In order to make a type formattable via ``std::ostream `` you should provide a
500
- ``formatter `` specialization inherited from ``ostream_formatter ``::
489
+ user-defined types that have an overloaded insertion operator (``operator<< ``)::
501
490
502
491
#include <fmt/ostream.h>
503
492
@@ -511,12 +500,13 @@ In order to make a type formattable via ``std::ostream`` you should provide a
511
500
}
512
501
};
513
502
514
- template <> struct fmt::formatter<date> : ostream_formatter {};
515
-
516
503
std::string s = fmt::format("The date is {}", date(2012, 12, 9));
517
504
// s == "The date is 2012-12-9"
518
505
519
- .. doxygenfunction :: print(std::ostream &os, format_string<T...> fmt, T&&... args)
506
+ {fmt} only supports insertion operators that are defined in the same namespaces
507
+ as the types they format and can be found with the argument-dependent lookup.
508
+
509
+ .. doxygenfunction :: print(std::basic_ostream<Char> &os, const S &format_str, Args&&... args)
520
510
521
511
.. _printf-api :
522
512
0 commit comments