From ef0bc8366cbdb9a11d44333d6014a231cc93ee31 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Mon, 14 Jul 2025 12:33:50 +0200 Subject: [PATCH] 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*. --- lib/base/logger.cpp | 10 +--------- lib/base/logger.hpp | 7 +++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 38a2c6721..b3be523a8 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -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; -} diff --git a/lib/base/logger.hpp b/lib/base/logger.hpp index 7b4758d8b..0437ebf39 100644 --- a/lib/base/logger.hpp +++ b/lib/base/logger.hpp @@ -119,17 +119,15 @@ public: ~Log(); template - Log& operator<<(const T& val) + Log& operator<<(T&& val) { if (!m_IsNoOp) { - m_Buffer << val; + m_Buffer << std::forward(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*&); }