sheeldotme
sheeldotme

Reputation: 2503

How do I reliably format std::vector<bool> with fmt's range support?

I'm getting inconsistent behaviour trying to format a vector of bools across different environments:

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

int main() {
    std::vector<bool> vec = {true, false, true};
    fmt::print("Vector contents: {}\n", vec);
    return 0;
}

This works fine in several environments:

But fails on:

With this error:

error: implicit instantiation of undefined template 'fmt::detail::type_is_unformattable_for<std::vector<bool>, char>'

All tests use fmt from trunk and c++23. What's causing this inconsistency and how can I fix it?

Upvotes: 2

Views: 110

Answers (1)

sheeldotme
sheeldotme

Reputation: 2503

Adding the fmt/std.h resolved the issue as it provides the formatter for the proxy type used by vector<bool>.

#include <fmt/std.h>

More details: https://github.com/fmtlib/fmt/issues/4026

Upvotes: 5

Related Questions