diff --git a/doc/api.md b/doc/api.md index 86808fc1..03a1d77d 100644 --- a/doc/api.md +++ b/doc/api.md @@ -511,7 +511,7 @@ chrono-format-specifications). ::: ptr(const std::shared_ptr&) -### Formatting Variants +### Variants A `std::variant` is only formattable if every variant alternative is formattable, and requires the `__cpp_lib_variant` [library @@ -527,6 +527,23 @@ feature](https://en.cppreference.com/w/cpp/feature_test). fmt::print("{}", std::variant()); // Output: variant(monostate) +## Bit-Fields and Packed Structs + +To format a bit-field or a field of a struct with `__attribute__((packed))` +applied to it, you need to convert it to the underlying or compatible type via +a cast or a unary `+` ([godbolt](https://www.godbolt.org/z/3qKKs6T5Y)): + +```c++ +struct smol { + int bit : 1; +}; + +auto s = smol(); +fmt::print("{}", +s.bit); +``` + +This is a known limitation of "perfect" forwarding in C++. + ## Format String Compilation