fmt icon indicating copy to clipboard operation
fmt copied to clipboard

Improve diagnostic to suggest fmt/ranges.h

Open marksantaniello opened this issue 1 year ago • 1 comments

The container support in fmt/ranges.h is extremely powerful, but I often forget that it exists. Could we have a specific error message in the event that we encounter an unformattable type that appears to be a range?

marksantaniello avatar Sep 03 '24 17:09 marksantaniello

I think we could check if the type has begin / end and provide a better diagnostic in that case.

vitaut avatar Sep 03 '24 18:09 vitaut

@vitaut I was taking a look at this

I believe we'd need to move the detail::is_range_ check from ranges.h to base.h (or format.h?). It only depends on the std header type_traits so includes don't change

These lines would move: https://github.com/fmtlib/fmt/blob/75e5be6adc294f5c7774b8b6ebbef1b1979fad86/include/fmt/ranges.h#L47-L114

And then have a SFINAE alternative if is_range_ is true to the generic error type at: https://github.com/fmtlib/fmt/blob/75e5be6adc294f5c7774b8b6ebbef1b1979fad86/include/fmt/base.h#L2207-L2212 saying a similar error message plus "did you forget to include fmt/ranges.h?"

Does that sound acceptable to you?

Arghnews avatar Nov 14 '24 08:11 Arghnews

Thinking more of it, this seems like a bad idea because it would create a weird special case for ranges which is only one of many standard formatters. It is also unnecessary with modules.

But thanks, @Arghnews, for looking into it anyway.

vitaut avatar Nov 14 '24 16:11 vitaut