#include
#include
#include
struct Point {
int x = 0;
int y = 0;
int z = 0;
};
template
struct std::formatter : std::formatter {
// v1
//auto format(const Point& p, auto& ctx) const {
// const auto [x, y, z] = p;
// return std::format_to(ctx.out(), "(x={}, y={}, z={})", x, y, z);
//}
// v2
auto format(const Point& p, std::format_context& ctx) const {
const auto [x, y, z] = p;
return std::format_to(ctx.out(), "(x={}, y={}, z={})", x, y, z);
}
};
int main() {
const Point p{ 1, 2, 3 };
std::println("{}", p); // compiles both in v1, and v2
const auto points = std::to_array({ {1, 2, 3}, {4, 5, 6}, {7, 8, 9} });
std::println("{}", points); // compiles only in v1
}
< /code>
Каковы правильные типы параметров для формата? Если так, какой именно?>
Подробнее здесь: https://stackoverflow.com/questions/797 ... ormat-spec
Каковы правильные параметры и типы возврата для специализации формата :: Formatter :: Format? ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение