#include <string>#include <string_view>#include <type_traits>#include <fmt/format.h>| Namespaces | |
| drake | |
| Macros | |
| #define | DRAKE_FMT8_CONST const | 
| When using fmt >= 8, this is defined to be constto indicate that thefmt::formatter<T>::format(...)function should be object-const.  More... | |
| #define | DRAKE_FORMATTER_AS(TEMPLATE_ARGS, NAMESPACE, TYPE, ARG, EXPR) | 
| Adds a fmt::formatter<NAMESPACE::TYPE>template specialization that formats theTYPEby delegating the formatting using a transformed expression, as if a conversion function like this were interposed during formatting:  More... | |
| Functions | |
| auto | fmt_runtime (std::string_view s) | 
| When using fmt >= 8, this is an alias for fmt::runtime.  More... | |
| template<typename T > | |
| std::string fmt_floating_point(T x) requires(std std::string | fmt_floating_point (T x) requires(!(std | 
| Returns fmt::to_string(x)but always with at least one digit after the decimal point.  More... | |
| std::string | fmt_debug_string (std::string_view x) | 
| Returns fmt::("{:?}", x), i.e, using fmt's "debug string format"; see https://fmt.dev docs for the '?' presentation type for details.  More... | |
| #define DRAKE_FMT8_CONST const | 
When using fmt >= 8, this is defined to be const to indicate that the fmt::formatter<T>::format(...) function should be object-const. 
When using fmt < 8, the function signature was incorrect (lacking the const), so this macro will be empty.
| #define DRAKE_FORMATTER_AS | ( | TEMPLATE_ARGS, | |
| NAMESPACE, | |||
| TYPE, | |||
| ARG, | |||
| EXPR | |||
| ) | 
Adds a fmt::formatter<NAMESPACE::TYPE> template specialization that formats the TYPE by delegating the formatting using a transformed expression, as if a conversion function like this were interposed during formatting: 
For example, this declaration ...
... changes this code ...
... to be equivalent to ...
... allowing user to format my_namespace::MyType objects without manually adding the to_string call every time.
This provides a convenient mechanism to add formatters for classes that already have a to_string function, or classes that are just thin wrappers over simple types (ints, enums, etc.).
Always use this macro in the global namespace, and do not use a semicolon (;) afterward.
| TEMPLATE_ARGS | The optional first argument TEMPLATE_ARGScan be used in case theTYPEis templated, e.g., it might commonly be set totypename T. It should be left empty when the TYPE is not templated. In caseTYPEhas multiple template arguments, note that macros will fight with commas so you should usetypename... Tsinstead of writing them all out. | 
| NAMESPACE | The namespace that encloses the TYPEbeing formatted. Cannot be empty. For nested namespaces, use intermediate colons, e.g.,drake::common. Do not place leading colons on theNAMESPACE. | 
| TYPE | The class name (or struct name, or enum name, etc.) being formatted. Do not place leading double-colons on the TYPE. If the type is templated, use the template arguments here, e.g.,MyOptional<T>ifTEMPLATE_ARGSwas chosen astypename T. | 
| ARG | A placeholder variable name to use for the value (i.e., object) being formatted within the EXPRexpression. | 
| EXPR | An expression to returnfrom the format_as function; it can refer to the givenARGname which will be of typeconst TYPE& ARG. The evaluated expression can only ever throw exceptions thatstd::string's default allocator might throw (i.e.,std::bad_alloc). | 
format_as customization point with this feature built-in. If so, then we can update this macro to use that spelling, and eventually deprecate the macro once Drake drops support for earlier version of fmt.