From 9964f44d25b0f9363f47be5f15066752c3f35c46 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Sat, 17 Apr 2021 16:21:16 +0100 Subject: [PATCH] Use std::void_t (C++17 feature) --- src/blackmisc/inheritancetraits.h | 9 +++--- src/blackmisc/typetraits.h | 51 +++++++++++++------------------ 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/blackmisc/inheritancetraits.h b/src/blackmisc/inheritancetraits.h index d49d4eaa6..d1a6d812a 100644 --- a/src/blackmisc/inheritancetraits.h +++ b/src/blackmisc/inheritancetraits.h @@ -11,7 +11,6 @@ #ifndef BLACKMISC_INHERITANCE_TRAITS_H #define BLACKMISC_INHERITANCE_TRAITS_H -#include "blackmisc/typetraits.h" // for void_t #include template @@ -24,14 +23,14 @@ namespace BlackMisc /*! * If T has a member typedef base_type, this trait will obtain it, otherwise void. */ - template > + template > struct TBaseOf { using type = void; //!< void }; //! \cond template - struct TBaseOf> + struct TBaseOf> { using type = typename T::base_type; //!< T::base_type }; @@ -50,14 +49,14 @@ namespace BlackMisc /*! * If T has a member typedef base_type which has a member propertyByIndex, this trait will obtain it, otherwise void. */ - template > + template > struct TIndexBaseOf { using type = void; //!< void }; //! \cond template - struct TIndexBaseOf().propertyByIndex(std::declval()))>> + struct TIndexBaseOf().propertyByIndex(std::declval()))>> { using type = typename T::base_type; //!< T::base_type }; diff --git a/src/blackmisc/typetraits.h b/src/blackmisc/typetraits.h index a10a11619..5ace19788 100644 --- a/src/blackmisc/typetraits.h +++ b/src/blackmisc/typetraits.h @@ -21,13 +21,6 @@ namespace BlackMisc class CPropertyIndexRef; - //! \cond PRIVATE - // Own implementation of C++17 std::void_t, simple variadic alias - // template which is always void. Useful for expression SFINAE. - template - using void_t = void; - //! \endcond - namespace Private { //! \private Own implementation of C++17 std::is_nothrow_swappable. @@ -74,103 +67,103 @@ namespace BlackMisc /*! * Trait to detect whether T contains a member function toQString. */ - template > + template > struct THasToQString : public std::false_type {}; //! \cond template - struct THasToQString().toQString())>> : public std::true_type {}; + struct THasToQString().toQString())>> : public std::true_type {}; //! \endcond /*! * Trait which is true if the expression a.push_back(v) is valid when a and v are instances of T and T::value_type. */ - template > + template > struct THasPushBack : public std::false_type {}; //! \cond template - struct THasPushBack().push_back(std::declval()))>> : public std::true_type {}; + struct THasPushBack().push_back(std::declval()))>> : public std::true_type {}; //! \endcond /*! * Trait to detect whether a class T has a static member function named getLogCategories. */ - template > + template > struct THasGetLogCategories : public std::false_type {}; //! \cond template - struct THasGetLogCategories> : public std::true_type {}; + struct THasGetLogCategories> : public std::true_type {}; //! \endcond /*! * Trait to detect whether a class T can be used as a key in a QHash. */ - template > + template > struct TModelsQHashKey : public std::false_type {}; //! \cond template - struct TModelsQHashKey() == std::declval(), qHash(std::declval()))>> : public std::true_type {}; + struct TModelsQHashKey() == std::declval(), qHash(std::declval()))>> : public std::true_type {}; //! \endcond /*! * Trait to detect whether a class T can be used as a key in a QMap. */ - template > + template > struct TModelsQMapKey : public std::false_type {}; //! \cond template - struct TModelsQMapKey() < std::declval())>> : public std::true_type {}; + struct TModelsQMapKey() < std::declval())>> : public std::true_type {}; //! \endcond /*! * Trait which is true if the expression compare(a, b) is valid when a and b are instances of T and U. */ - template > + template > struct THasCompare : public std::false_type {}; //! \cond template - struct THasCompare(), std::declval()))>> : public std::true_type {}; + struct THasCompare(), std::declval()))>> : public std::true_type {}; //! \endcond /*! * Trait which is true if the expression a.compareByPropertyIndex(b, i) is valid when a and b are instances of T, * and i is an instance of CPropertyIndexRef. */ - template > + template > struct THasComparePropertyByIndex : public std::false_type {}; //! \cond template - struct THasComparePropertyByIndex().comparePropertyByIndex(std::declval(), std::declval()))>> : public std::true_type {}; + struct THasComparePropertyByIndex().comparePropertyByIndex(std::declval(), std::declval()))>> : public std::true_type {}; //! \endcond /*! * Trait which is true if the expression a.propertyByIndex(i) is valid with a is an instance of T and i is an * instance of CPropertyIndexRef. */ - template > + template > struct THasPropertyByIndex : public std::false_type {}; //! \cond template - struct THasPropertyByIndex().propertyByIndex(std::declval()))>> : public std::true_type {}; + struct THasPropertyByIndex().propertyByIndex(std::declval()))>> : public std::true_type {}; //! \endcond /*! * Trait which is true if the expression a == b is valid when a and b are instances of T and U. */ - template > + template > struct TIsEqualityComparable : public std::false_type {}; //! \cond template - struct TIsEqualityComparable() == std::declval())>> : public std::true_type {}; + struct TIsEqualityComparable() == std::declval())>> : public std::true_type {}; //! \endcond /*! * Trait which is true if T has methods marshallToDbus and unmarshallFromDbus. */ - template > + template > struct THasMarshallMethods : public std::false_type {}; //! \cond template - struct THasMarshallMethods().marshallToDbus(std::declval()), + struct THasMarshallMethods().marshallToDbus(std::declval()), std::declval().unmarshallFromDbus(std::declval()))>> : public std::true_type {}; //! \endcond @@ -189,11 +182,11 @@ namespace BlackMisc /*! * Trait that detects if a type is QPrivateSignal. */ - template > + template > struct TIsQPrivateSignal : public std::false_type {}; //! \cond template - struct TIsQPrivateSignal::QPrivateSignal>> : public std::is_same::QPrivateSignal> {}; + struct TIsQPrivateSignal::QPrivateSignal>> : public std::is_same::QPrivateSignal> {}; //! \endcond }