diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 9b85a41266..be21526339 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -41,6 +41,7 @@ #include #include #include +#include #ifndef QTYPEINFO_H #define QTYPEINFO_H @@ -342,12 +343,16 @@ namespace QTypeTraits */ namespace detail { -// find out whether T has a value_type typedef +// find out whether T is a conteiner // this is required to check the value type of containers for the existence of the comparison operator template -struct has_value_type : std::false_type {}; +struct is_container : std::false_type {}; template -struct has_value_type> : std::true_type {}; +struct is_container().begin() != std::declval().end()), bool>, + typename T::value_type +>> : std::true_type {}; + // Checks the existence of the comparison operator for the class itself template @@ -357,7 +362,7 @@ struct has_operator_equal() : std::true_type {}; // Two forward declarations -template::value> +template::value> struct expand_operator_equal_container; template struct expand_operator_equal_tuple; @@ -366,7 +371,7 @@ struct expand_operator_equal_tuple; template using expand_operator_equal = expand_operator_equal_container; -// if T doesn't have a value_type member check if it's a tuple like object +// if T isn't a container check if it's a tuple like object template struct expand_operator_equal_container : expand_operator_equal_tuple {}; // if T::value_type exists, check first T::value_type, then T itself @@ -380,6 +385,8 @@ using expand_operator_equal_recursive = std::conjunction struct expand_operator_equal_tuple : has_operator_equal {}; +template +struct expand_operator_equal_tuple> : has_operator_equal {}; template struct expand_operator_equal_tuple> : expand_operator_equal_recursive {}; template @@ -394,7 +401,7 @@ template struct has_operator_less_than() < std::declval()))>> : std::true_type{}; -template::value> +template::value> struct expand_operator_less_than_container; template struct expand_operator_less_than_tuple; diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 35d3f433ec..3d729eae67 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -101,6 +101,11 @@ static_assert(!QTypeTraits::has_operator_less_than_v>); static_assert(!QTypeTraits::has_operator_equal_v>); static_assert(!QTypeTraits::has_operator_less_than_v>); +// QSharedPointer +static_assert(QTypeTraits::has_operator_equal_v>); +// smart pointer equality doesn't depend on T +static_assert(QTypeTraits::has_operator_equal_v>); + // std::vector static_assert(QTypeTraits::has_operator_equal_v>); static_assert(QTypeTraits::has_operator_less_than_v>); @@ -127,6 +132,10 @@ static_assert(QTypeTraits::has_operator_less_than_v>); static_assert(!QTypeTraits::has_operator_equal_v>); static_assert(!QTypeTraits::has_operator_less_than_v>); +// std::optional +static_assert(QTypeTraits::has_operator_equal_v>); +static_assert(!QTypeTraits::has_operator_equal_v>); + // nested types static_assert(QTypeTraits::has_operator_equal_v); static_assert(!QTypeTraits::has_operator_less_than_v);