diff --git a/src/blackmisc/logmessage.h b/src/blackmisc/logmessage.h index c30b4cb0f..c58d0be24 100644 --- a/src/blackmisc/logmessage.h +++ b/src/blackmisc/logmessage.h @@ -24,6 +24,25 @@ namespace BlackMisc { + /*! + * Trait to detect whether T contains a member toQString. + */ + template + class HasToQString + { + // http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector + struct Fallback { int toQString; }; + template struct int_t { typedef int type; }; + template ::value> struct Derived : public U, public Fallback {}; + template struct Derived : public Fallback {}; + template static char test(typename int_t<&Derived::toQString>::type); + template static int test(...); + + public: + //! True if T contains a member toQString. + static const bool value = sizeof(test(0)) > 1; + }; + /*! * Helper with static methods for dealing with metadata embedded in log message category strings. * @@ -138,7 +157,7 @@ namespace BlackMisc CLogMessage &operator <<(QChar v) { return arg(v); } CLogMessage &operator <<(char v) { return arg(QChar(v)); } CLogMessage &operator <<(double v) { return arg(QString::number(v)); } - template ::value>::type> + template ::value>::type> CLogMessage &operator <<(const T &v) { return arg(v.toQString()); } //! @}