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

Added format_as for std::vector<bool>::reference #3569

Closed
wants to merge 1 commit into from

Conversation

felix642
Copy link
Contributor

@felix642 felix642 commented Aug 3, 2023

Added a format_as entry to support std::vector<bool>::reference.

closes #3567

@felix642 felix642 marked this pull request as draft August 3, 2023 13:14
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. Please use format_as instead of a macro and move this to fmt/std.h.

@felix642 felix642 force-pushed the format_as_vector_bool branch from 92e9a7f to 8cb0961 Compare August 4, 2023 01:53
@felix642
Copy link
Contributor Author

felix642 commented Aug 4, 2023

Hi  @vitaut, thank you for the feedback. I've moved the format_as method to the std.h file and changed the macro for a template.

From what I can see I need to inject this specialization into the standard namespace which is probably not something that we want. I also saw this comment in the code for another specialization:
// This is defined in core.h instead of format.h to avoid injecting in std.

Do we want to do the same with this method ?

@vitaut
Copy link
Contributor

vitaut commented Aug 4, 2023

You are right, injecting format_as into the std namespace is not a good idea. Let's define a formatter specialization that derives from formatter<bool> instead.

@phprus
Copy link
Contributor

phprus commented Aug 4, 2023

@vitaut
We can't implement formatter for std::vector<bool>::reference without fix issue #2979 because std::vector<bool>::reference has an overloaded operator&:

/Users/phprus/Devel/fmt/include/fmt/core.h:1286:20: error: const_cast from '__bit_iterator<std::vector<bool>, false>' to 'value_type *' (aka 'std::__bit_reference<std::vector<bool>, true> *') is not allowed custom.value = const_cast<value_type*>(&val);

@phprus
Copy link
Contributor

phprus commented Aug 4, 2023

Another solution: #3570

@vitaut
Copy link
Contributor

vitaut commented Aug 5, 2023

Closing in favor of #3570 but thanks for your work!

@vitaut vitaut closed this Aug 5, 2023
@felix642 felix642 deleted the format_as_vector_bool branch August 22, 2023 17:29
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.

Formatting element of std::vector<bool> fails
3 participants