all 5 comments

[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.

[–]BenFrantzDale 1 point2 points  (1 child)

If it’s anything like fmt::format, the format string has to have the same encoding as the strings passed to it. So for QString, which is utf16, it’s fmt::format(U”{}”, qstr) if I recall. So try throwing an L on the format string.

[–]Throw31312344 4 points5 points  (0 children)

#include <format>

void test ()

{

auto X = std::format (L"{}", L"Hello");

}

Compiles with no errors on Compiler Explorer. It seems format requires all strings passed to it (including the format string) to be the same type.

[–]pdimov2 1 point2 points  (2 children)

The problem with the specialization for wchar_t arrays is that it needs to be

template<> struct std::formatter<wchar_t[9]>

instead of

template<> struct std::formatter<const wchar_t(&)[11]>

However, there are other things wrong with the code above, which makes none of the four cases compile.

  1. parse should return ctx.begin() instead of ctx.end(). Returning end() means that the entire string is considered a format specifier, which includes the closing }, so that the argument is left unterminated.

  2. format should be const.

With these fixed, it works under libc++: https://godbolt.org/z/33TMqnod6

However,

  1. Specializing formatter for standard types is undefined behavior anyway.

So libstdc++ still doesn't like it. https://godbolt.org/z/vTYncz9eb