-
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
Add formatters for container adapters #3279
Conversation
d2aad2d
to
82175fe
Compare
82175fe
to
6154473
Compare
include/fmt/ranges.h
Outdated
struct formatter<T, Char, | ||
enable_if_t<detail::is_container_adaptor_like<T>::value>> { | ||
private: | ||
struct formatter<typename T::container_type, Char> container_formatter; |
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.
struct
not needed here and I suggest using inheritance instead of composition to avoid redefining parse
.
Also please apply clang-format, indent is a bit off.
Thank you! |
// Note: The output is formatted as a string because the underlying | ||
// container is a string. This behavior is conforming to the standard | ||
// [container.adaptors.format]. |
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 inconsistent with formatting containers and looks like an oversight. I think we should open an LWG issue.
Close #3215.
https://eel.is/c++draft/container.adaptors.format specifies formatting for container adapters (
std::stack
,std::queue
, andstd::priority_queue
in particular).Not sure if the implementation should go into
ranges.h
orstd.h
. I'm putting it inranges.h
for now because I don't want to makestd.h
depend onranges.h
.Container adapters have a protected member
Container c
, which can be exposed by defining a derived class.