Make qRegisterMetaType constexpr for built-in types.
For consistency with qMetaTypeId, and because we can. Change-Id: I6882a16ef3c0d84539048c9f2c201c4a2b2ca7ad Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
a5b0290497
commit
dec9666dd4
@ -639,7 +639,7 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId(
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline int qRegisterMetaType(
|
||||
inline Q_DECL_CONSTEXPR int qRegisterMetaType(
|
||||
#if !defined(qdoc) && !defined(Q_CC_SUN)
|
||||
T * dummy = 0
|
||||
#endif
|
||||
|
@ -1681,11 +1681,19 @@ void tst_QMetaType::metaObject()
|
||||
#define METATYPE_ID_FUNCTION(Type, MetaTypeId, Name) \
|
||||
case ::qMetaTypeId< Name >(): metaType = MetaTypeIdStruct<MetaTypeId>::Value;
|
||||
|
||||
#define REGISTER_METATYPE_FUNCTION(Type, MetaTypeId, Name) \
|
||||
case qRegisterMetaType< Name >(): metaType = RegisterMetaTypeStruct<MetaTypeId>::Value;
|
||||
|
||||
template<int>
|
||||
struct MetaTypeIdStruct
|
||||
{
|
||||
};
|
||||
|
||||
template<int>
|
||||
struct RegisterMetaTypeStruct
|
||||
{
|
||||
};
|
||||
|
||||
#define METATYPE_ID_STRUCT(Type, MetaTypeId, Name) \
|
||||
template<> \
|
||||
struct MetaTypeIdStruct< ::qMetaTypeId< Name >()> \
|
||||
@ -1693,14 +1701,28 @@ struct MetaTypeIdStruct< ::qMetaTypeId< Name >()> \
|
||||
enum { Value = ::qMetaTypeId< Name >() }; \
|
||||
};
|
||||
|
||||
#define REGISTER_METATYPE_STRUCT(Type, MetaTypeId, Name) \
|
||||
template<> \
|
||||
struct RegisterMetaTypeStruct<qRegisterMetaType< Name >()> \
|
||||
{ \
|
||||
enum { Value = qRegisterMetaType< Name >() }; \
|
||||
};
|
||||
|
||||
#if defined(Q_COMPILER_CONSTEXPR)
|
||||
QT_FOR_EACH_STATIC_TYPE(METATYPE_ID_STRUCT)
|
||||
QT_FOR_EACH_STATIC_TYPE(REGISTER_METATYPE_STRUCT)
|
||||
|
||||
template<int i = ::qMetaTypeId<int>()>
|
||||
struct MetaTypeIdStructDefaultTemplateValue
|
||||
{
|
||||
enum { Value };
|
||||
};
|
||||
|
||||
template<int i = qRegisterMetaType<int>()>
|
||||
struct RegisterMetaTypeStructDefaultTemplateValue
|
||||
{
|
||||
enum { Value };
|
||||
};
|
||||
#endif
|
||||
|
||||
void tst_QMetaType::constexprMetaTypeIds()
|
||||
@ -1715,6 +1737,14 @@ void tst_QMetaType::constexprMetaTypeIds()
|
||||
#endif
|
||||
default:;
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
#if defined(Q_COMPILER_CONSTEXPR)
|
||||
QT_FOR_EACH_STATIC_TYPE(REGISTER_METATYPE_FUNCTION)
|
||||
metaType = RegisterMetaTypeStructDefaultTemplateValue<>::Value;
|
||||
#endif
|
||||
default:;
|
||||
}
|
||||
Q_UNUSED(metaType);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user