The documentation is not extremely clear about the difference between the 3 ways I found to have compile-time format string checks. I would like to try to PR an improvement to the documentation, but first I need to be sure
FMT_STRING version, but not using a macro is nice, or is the speed boost from FMT_COMPILE usually worth it?Bonus question, is there one which has a chance to land in std::format?
Is there a difference as to what they can check?
Yes, FMT_STRING always does compile-time checks while _format only if a compiler supports UDL templates extensions.
Is there a preferred one?
FMT_STRING and FMT_COMPILE serve different purposes. If you only need checks then use FMT_STRING. If you want to avoid format string parsing overhead then use FMT_COMPILE (this is rarely needed) and note that:
Format string compilation can generate more binary code compared to the default API and is only recommended in places where formatting is a performance bottleneck.
Thanks for clarifying. I would say the documentation could be more explicit. I gave it a try.
Most helpful comment
Yes,
FMT_STRINGalways does compile-time checks while_formatonly if a compiler supports UDL templates extensions.FMT_STRINGandFMT_COMPILEserve different purposes. If you only need checks then useFMT_STRING. If you want to avoid format string parsing overhead then useFMT_COMPILE(this is rarely needed) and note that: