Fix format_as for tuple-like types with ranges.h - #4945
Conversation
vitaut
left a comment
There was a problem hiding this comment.
Thanks for the PR. I think format_as should indeed take precedence over tuple formatting, but I’d prefer not to change the semantics of is_tuple_formattable.
fmt::is_tuple_formattable is an exported trait and currently answers whether the tuple elements are formattable. With this change it becomes false for every tuple-like type that has format_as, even if all of its elements are formattable. Could we instead keep is_tuple_formattable_ unchanged and exclude format_as when selecting the tuple formatter, while still making sure the tuple formattability check is not instantiated in that case?
Nit: could you also replace the \n escapes in the PR description with actual newlines? The current description is a bit odd to read/edit.
|
Updated in 4d5286b (amended after CI showed the public tuple-formattability value is intentionally unchanged for this recursive tuple-like test type).
Validation: |
e8b75bc to
d3419f1
Compare
d3419f1 to
4d5286b
Compare
|
Implemented and pushed commit 57dc090. This preserves the public |
|
Follow-up: corrected the regression assertion to pass the required |
|
Follow-up: the exported trait assertion now uses |
vitaut
left a comment
There was a problem hiding this comment.
Mostly looks good, just one more inline comment.
| template <typename T, typename = void> | ||
| struct has_format_as_ : std::false_type {}; | ||
| template <typename T> | ||
| struct has_format_as_<T, void_t<format_as_result<T>>> : std::true_type {}; |
There was a problem hiding this comment.
This can be folded into is_tuple_formattable_for_formatter.
There was a problem hiding this comment.
Folded the format_as detection into is_tuple_formattable_for_formatter so the helper directly defaults to the exported tuple trait and specializes to false only when format_as_result<T> is valid. Pushed as 83c869a; git diff --check passes.
|
Merged, thanks |
Fixes #4944
A tuple-like type can also provide an ADL
format_asfunction. The tuple formattability probe should defer to that formatter instead of recursively checking tuple elements.This change detects
format_asbefore probing tuple elements, so the existingformat_asformatter takes precedence.Tests: