summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-03-23 12:25:33 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-27 19:26:45 +0200
commitf1963324d26e825cd4cce3f666702933b86d92c8 (patch)
tree197e5a6fa78a310273e0c530b81c80b579e91d0f
parent59a5c78e20db507b4b21893ab9e4e833543e436e (diff)
QUuid: mark constructors constexpr
See e.g. f3141c58badbd2da9eb42 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>
-rw-r--r--src/corelib/plugin/quuid.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h
index dee97d93a5..05f44b4c25 100644
--- a/src/corelib/plugin/quuid.h
+++ b/src/corelib/plugin/quuid.h
@@ -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)
{