plog
plog copied to clipboard
plog cannot find user's custom operator<< from user's namespace.
plog::Record might break some idiom code like the following example.
Without using mine::operator<<; the p_log function would get a compiler error no match for ‘operator<<’ (operand types are ‘plog::util::nostringstream’ {aka ‘std::__cxx11::basic_ostringstream<char>’} and ‘const third_party::A’). c_log and ss_log work fine anyway.
#include <plog/Log.h>
#include <iostream>
#include <plog/Appenders/ConsoleAppender.h>
namespace third_party {
struct A {
int a;
};
} // namespace third_party
namespace mine {
std::ostream& operator<<(std::ostream& os, const third_party::A& a) {
return os << "mine::operator<< A" << a.a;
}
void c_log(const third_party::A& a) { std::clog << "c_log A{" << a << "}\n"; }
void ss_log(const third_party::A& a) {
std::ostringstream oss;
oss << "ss_log A{" << a << "}\n";
std::clog << oss.str();
}
void p_log(const third_party::A& a) { LOGI << "p_log A{" << a << "}"; }
} // namespace mine
namespace plog {
//using mine::operator<<;
} // namespace plog
int main() {
plog::ConsoleAppender<plog::TxtFormatter> s;
plog::init(plog::verbose, &s);
third_party::A a = {42};
mine::c_log(a);
mine::ss_log(a);
mine::p_log(a);
return 0;
}
The issue is confirmed. Thanks for a good report.
Hi, is this issue resolved?? is there any workaround for this? is this issue because of Visual Studio 2017?
Hi @bhatiahs ,
No, it's still actual and it's not related to VS2017. A workaround is suggested by the issue author:
namespace plog {
using mine::operator<<;
}