使用spdlog
进行格式化时,是否可以扩展{}
来支持自定义结构作为项?
所以当我有一个
struct p {
int x;
int y;
int z;
};
p my_p;
我想做
spdlog::info("p = {}", my_p);
// after registering some kind of formatter object for {p}
代替
spdlog::info("p = (x={}, y={}, z={})", my_p.x, my_p.y, my_p.z);
答案 0 :(得分:1)
#include "spdlog/spdlog.h"
#include "spdlog/fmt/ostr.h" // must be included
class some_class {};
std::ostream& operator<<(std::ostream& os, const some_class& c)
{
return os << "some_class";
}
请参阅https://github.com/gabime/spdlog/wiki/1.-QuickStart#log-user-defined-objects