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

Restore constraint on map formatter #4326

Merged
merged 3 commits into from
Jan 25, 2025

Conversation

timsong-cpp
Copy link
Contributor

@timsong-cpp timsong-cpp commented Jan 23, 2025

So that it correctly reports as unformattable when the element is.

This was lost when the formatter was split out in 77bfd84

Copy link
Contributor

@vitaut vitaut left a 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! Looks good, just a minor question inline.

@@ -65,6 +67,9 @@ TEST(ranges_test, format_vector) {
EXPECT_EQ(fmt::format("{:n}", vvc), "['a', 'b', 'c'], ['a', 'b', 'c']");
EXPECT_EQ(fmt::format("{:n:n}", vvc), "'a', 'b', 'c', 'a', 'b', 'c'");
EXPECT_EQ(fmt::format("{:n:n:}", vvc), "a, b, c, a, b, c");

EXPECT_FALSE((fmt::is_formattable<unformattable>::value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are extra parentheses needed here and in other places below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. They were in the original (I moved this assertion up from the tuple one) so I just went with it, but I can remove the unnecessary ones.

@@ -83,6 +88,8 @@ TEST(ranges_test, format_map) {
auto m = std::map<std::string, int>{{"one", 1}, {"two", 2}};
EXPECT_EQ(fmt::format("{}", m), "{\"one\": 1, \"two\": 2}");
EXPECT_EQ(fmt::format("{:n}", m), "\"one\": 1, \"two\": 2");

EXPECT_FALSE((fmt::is_formattable<std::map<int, unformattable>>::value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this is the only place that needs extra parentheses because of a comma.

@vitaut vitaut merged commit cb6fdf2 into fmtlib:master Jan 25, 2025
45 checks passed
@vitaut
Copy link
Contributor

vitaut commented Jan 25, 2025

Merged, thanks!

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.

2 participants