-
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
Support character range formatting #3863
Conversation
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!
include/fmt/ranges.h
Outdated
template <typename R, typename FormatContext> | ||
template <typename R, typename FormatContext, typename U = T, | ||
enable_if_t<std::is_same<U, Char>::value, bool> = true> | ||
auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) { |
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.
To avoid duplication let's merge the two format
overloads and either use if constexpr or move only the string-specific logic into a separate function.
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.
I tried if constexpr
but its introduced in C++17, so tests would break. I pushed the changes to make the string logic a separate function, though I'm unsure if there's a way to cleanly handle the non-Char case, so any advice here would be appreciated.
@vitaut Thanks for the comments, pushed the latest changes |
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.
Looks good, just one remaining (minor) comment.
Merged, thank you! |
My attempt to fix #3857. Implemented the
:s
and:?s
specifier for ranges of characters. Specifically for the debug case (:?s
), the underlying writer for escaped chars included single quotes in the output, so I converted the range into a string first. Added tests as well.