You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test code is listed below。It works well with version 8.0.1,but will get a compile error with newer version even the newest version 10.0.0。when build with 10.0.0,I uncomment two formmater in the code, just as the document list。
#include<fmt/ostream.h>
#include<iostream>classdate {
int year_, month_, day_;
public:date(int year, int month, int day): year_(year), month_(month), day_(day) {}
friend std::ostream& operator<<(std::ostream& os, const date& d) {
return os << d.year_ << '-' << d.month_ << '-' << d.day_;
}
};
classMyVector3f {
public:float x = 1;
float y = 2;
float z = 3;
public:MyVector3f() {}
template <typename LocalType>
MyVector3f(const LocalType& v) {
this->x = v.x();
this->y = v.y();
this->z = v.z();
}
template <typename LocalType>
operatorLocalType() const {
LocalType v;
v.x() = this->x;
v.y() = this->y;
v.z() = this->z;
return v;
}
template <typename OStream>
friend OStream& operator<<(OStream& os, const MyVector3f& v) {
return os << "["
<< " x:" << v.x << ", y:" << v.y << ", z:" << v.z << "]";
}
};
// When build with 10.0.0, please uncomment the two lines below.// template <> struct fmt::formatter<date> : ostream_formatter {};// template <> struct fmt::formatter<MyVector3f> : ostream_formatter{};intmain()
{
std::string s = fmt::format("The date is {}", date(2012, 12, 9));
std::cout << s << std::endl;
std::string vs = fmt::format("vector3f is {}", MyVector3f());
std::cout << vs << std::endl;
}
The text was updated successfully, but these errors were encountered:
The problem is that MyVector3f has an implicit conversion operator that tries to convert to anything but fails if it doesn't have members x(), etc. which interferes with built-in {fmt}'s formatters. I would recommend constraining it, e.g.
test code is listed below。It works well with version 8.0.1,but will get a compile error with newer version even the newest version 10.0.0。when build with 10.0.0,I uncomment two formmater in the code, just as the document list。
The text was updated successfully, but these errors were encountered: