QUuid: mark constructors constexpr

See e.g. f3141c58ba for rationale.

The problematic part here is the array member
which in C++98 cannot be initialised in the
ctor-initializer-list. For this, C++11 Uniform
Initialisation is needed, for which Qt does
not yet have a Q_COMPILER_* macro. I'm not sure
we need one, either, since I doubt that there's
a compiler that implements std::initializer_list,
but not uniform initialisation.

Change-Id: I4fa8f4f9db8703096358634fb2e6f5de61f0fedd
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Marc Mutz 2012-03-23 12:25:33 +01:00 committed by Qt by Nokia
parent 59a5c78e20
commit f1963324d2
1 changed files with 16 additions and 0 deletions

View File

@ -84,6 +84,13 @@ public:
Sha1 = 5 // 0 1 0 1
};
#ifdef Q_COMPILER_INITIALIZER_LISTS // UNIFORM_INITIALIZATION
Q_DECL_CONSTEXPR QUuid()
: data1(0), data2(0), data3(0), data4{0,0,0,0,0,0,0,0} {}
Q_DECL_CONSTEXPR QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8)
: data1(l), data2(w1), data3(w2), data4{b1, b2, b3, b4, b5, b6, b7, b8} {}
#else
QUuid()
{
data1 = 0;
@ -106,6 +113,8 @@ public:
data4[6] = b7;
data4[7] = b8;
}
#endif
#ifndef QT_NO_QUUID_STRING
QUuid(const QString &);
QUuid(const char *);
@ -142,6 +151,12 @@ public:
#if defined(Q_OS_WIN)
// On Windows we have a type GUID that is used by the platform API, so we
// provide convenience operators to cast from and to this type.
#ifdef Q_COMPILER_INITIALIZER_LISTS // UNIFORM_INITIALIZATION
Q_DECL_CONSTEXPR QUuid(const GUID &guid)
: data1(guid.Data1), data2(guid.Data2), data3(guid.Data3),
data4{guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]} {}
#else
QUuid(const GUID &guid)
{
data1 = guid.Data1;
@ -150,6 +165,7 @@ public:
for(int i = 0; i < 8; i++)
data4[i] = guid.Data4[i];
}
#endif
QUuid &operator=(const GUID &guid)
{