Log: use std::forward in operator<< and remove overload for const char*

There already is a template operator<< implemented, so far only for const
references though. Changing this to perfectly forward the argument to the
corresponding operator in the underlying std::ostringstring allows handling all
the cases there, removing the need for a separate overload for const char*.
This commit is contained in:
Julian Brost 2025-07-14 12:33:50 +02:00
parent 8d15e7ff9a
commit ef0bc8366c
2 changed files with 4 additions and 13 deletions

View File

@ -27,6 +27,7 @@ template Log& Log::operator<<(const int&);
template Log& Log::operator<<(const unsigned long&);
template Log& Log::operator<<(const long&);
template Log& Log::operator<<(const double&);
template Log& Log::operator<<(const char*&);
REGISTER_TYPE(Logger);
@ -315,12 +316,3 @@ Log::~Log()
}
#endif /* _WIN32 */
}
Log& Log::operator<<(const char *val)
{
if (!m_IsNoOp) {
m_Buffer << val;
}
return *this;
}

View File

@ -119,17 +119,15 @@ public:
~Log();
template<typename T>
Log& operator<<(const T& val)
Log& operator<<(T&& val)
{
if (!m_IsNoOp) {
m_Buffer << val;
m_Buffer << std::forward<T>(val);
}
return *this;
}
Log& operator<<(const char *val);
private:
LogSeverity m_Severity;
String m_Facility;
@ -146,6 +144,7 @@ extern template Log& Log::operator<<(const int&);
extern template Log& Log::operator<<(const unsigned long&);
extern template Log& Log::operator<<(const long&);
extern template Log& Log::operator<<(const double&);
extern template Log& Log::operator<<(const char*&);
}