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

Formatting element of std::vector<bool> fails #3567

Closed
felix642 opened this issue Aug 2, 2023 · 1 comment
Closed

Formatting element of std::vector<bool> fails #3567

felix642 opened this issue Aug 2, 2023 · 1 comment

Comments

@felix642
Copy link
Contributor

felix642 commented Aug 2, 2023

Hi, the following code does not compile :

#include <vector>
#include <fmt/core.h>

int main()
{
    std::vector<bool> myVector = {false};
    
    fmt::print("{}", myVector[0]);
}

This is because std::vector bool as a specialisation where the elements are made space efficient.

Is there something already in place that allows me to format the value or do I need to cast the element when calling fmt::print()?

https://godbolt.org/z/91P18xKxK

@vitaut
Copy link
Contributor

vitaut commented Aug 3, 2023

I think this can be solved by adding a format_as overload that converts vector<bool> element type to bool. A PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants