Код: Выделить всё
#include
#include
#include
template
struct std::formatter {
constexpr auto parse(std::format_parse_context& ctx) {
// Simplified for this example, actually I want to implement a specific {:}
return ctx.begin();
}
auto format(std::string s, std::format_context& ctx) const {
for (char& c : s) {
c = std::toupper(static_cast(c));
}
return std::format_to(ctx.out(), "{:s}", s);
}
};
int main() {
const std::string s = "hello world";
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79755184/can-we-use-custom-formatters-for-std-strings[/url]
Мобильная версия