c++templatesgccclangfmt

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?


Solution

  • 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