Код: Выделить всё
template
requires requires (T v) {
{ v.format() } -> std::convertible_to;
}
struct std::formatter : formatter
{
auto format(T t, format_context& ctx) const
{
return formatter::format(t.format(), ctx);
}
};
Код: Выделить всё
template
requires requires (T v) {
{ v.format() } -> std::convertible_to;
}
struct std::formatter : formatter
{
auto format(std::list list, format_context& ctx) const
{
std::string result;
bool first = true;
for (T& item: list) {
if (!first)
result += ", ";
result += formatter::format(item.format(), ctx);
first = false;
}
return result;
}
};
Код: Выделить всё
/libutil/include/util/format.h:38:14: error: no match for ‘operator+=’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string’} and ‘std::basic_format_context::iterator’)
38 | result += formatter::format(item.format(), ctx);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Подробнее здесь: https://stackoverflow.com/questions/790 ... ble-things