-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix join for specific types (#1981) #2034
Conversation
std::declval<typename std::iterator_traits<It>::value_type>())); | ||
|
||
template <typename It, typename Char> | ||
using iterator_formatter = conditional_t< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely not so nice.
Also TBH I'm not sure that using FMT_BUFFER_CONTEXT
is correct here.
b47a944
to
93a09e3
Compare
Try to apply the same rules for iterator value type (join) as for regular types. Try to convert iterator value type to a formattable one. For instance if the join operation refers to an enum class iterator (such as std::byte) then try to use the enum class underlying type. Also try to use a fallback formatter if available.
93a09e3
to
10ea9a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
You shouldn't be changing the formatter
specialization for arg_join
. Instead it's enough to add a formatter specialization for byte using FORMAT_AS
here: https://github.com/fmtlib/fmt/blob/master/include/fmt/format.h#L3521 and add a cast in the implementation of FORMAT_AS
.
I agree that it would fix the
This works because of the conversion done here Line 1229 in 3f4839c
However
This does not work because no conversion occurs. Line 3679 in 3f4839c
Am I missing something? So I tried to apply the same conversion. |
Conversion is just an implementation detail. The current way of detecting if type is formattable is to check |
I'm sorry but I feel quiet confused. struct RouteWithEvents
{
...
};
inline std::ostream& operator<<(std::ostream& os, const RouteWithEvents& route_with_events)
{
return os << fmt::format("RouteWithEvents(Route: {}: {})", route_with_events.route, route_with_events.events_on_route);
}
using RoutesWithEvents = std::vector<RouteWithEvents>;
inline std::ostream& operator<<(std::ostream& os, const RoutesWithEvents& routes_with_events)
{
return os << fmt::format("RoutesWithEvents({})", fmt::join(routes_with_events, ", "));
} Unless I missed something, this just doesn't work since 6.0.0 version while it works nicely with the previous version (5.3.0). |
I'm OK with adding support for fallback formatter to |
Closing this in favor of |
Ok Thanks for your answer @vitaut! |
Try to apply the same rules for iterator value type (join) as for
regular types.
Try to convert iterator value type to a formattable one.
For instance if the join operation refers to an enum class iterator
(such as std::byte) then try to use the enum class underlying type.
Also try to use a fallback formatter if available.
I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.