refs #628 Use expression SFINAE and the void_t trick to simplify some type traits.

This commit is contained in:
Mathew Sutcliffe
2016-03-25 19:01:07 +00:00
parent f159bdb5bf
commit 7ce1b268df
8 changed files with 117 additions and 85 deletions

View File

@@ -17,6 +17,7 @@
#include "propertyindex.h"
#include "logcategorylist.h"
#include "timestampbased.h"
#include "typetraits.h"
#include <QReadWriteLock>
namespace BlackMisc
@@ -29,25 +30,6 @@ namespace BlackMisc
BLACKMISC_EXPORT QString arg(const QString &format, const QStringList &args);
}
/*!
* Trait to detect whether T contains a member toQString.
*/
template <typename T>
class HasToQString
{
// http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector
struct Fallback { int toQString; };
template <int Fallback:: *> struct int_t { using type = int; };
template <typename U, bool = std::is_class<U>::value> struct Derived : public U, public Fallback {};
template <typename U> struct Derived<U, false> : public Fallback {};
template <typename U> static char test(typename int_t<&Derived<U>::toQString>::type);
template <typename U> static int test(...);
public:
//! True if T contains a member toQString.
static const bool value = sizeof(test<T>(0)) > 1;
};
/*!
* Status severities
*/