mirror of
https://github.com/fmtlib/fmt.git
synced 2026-10-02 07:04:35 +08:00
Format an enum as its underlying value if the enum is annotated with
fmt::as_underlying, the equivalent of std::format_as_underlying from P4267:
enum class [[=fmt::as_underlying]] color { red = 1, green = 2, blue = 4 };
fmt::format("{:04x}", color::blue); // "0004"
The value is mapped before type erasure via the existing
formatter<T>::format_as hook, as in the std::byte formatter, so it is stored
as a builtin argument and can be used as dynamic width or precision.
Combining the annotation with fmt::as_identifiers is rejected with a
static_assert.