Skip to content
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

Merged
merged 6 commits into from
Feb 9, 2023

Conversation

ShawnZhong
Copy link
Contributor

Close #3215.

https://eel.is/c++draft/container.adaptors.format specifies formatting for container adapters (std::stack, std::queue, and std::priority_queue in particular).

Not sure if the implementation should go into ranges.h or std.h. I'm putting it in ranges.h for now because I don't want to make std.h depend on ranges.h.

Container adapters have a protected member Container c, which can be exposed by defining a derived class.

struct formatter<T, Char,
enable_if_t<detail::is_container_adaptor_like<T>::value>> {
private:
struct formatter<typename T::container_type, Char> container_formatter;
Copy link
Contributor

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.

@vitaut vitaut merged commit 581c629 into fmtlib:master Feb 9, 2023
@vitaut
Copy link
Contributor

vitaut commented Feb 9, 2023

Thank you!

Comment on lines +450 to +452
// 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].
Copy link
Contributor

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.

@ShawnZhong ShawnZhong deleted the container-adapter branch February 9, 2023 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add formatters for STL container adapters
2 participants