summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2011-04-04 10:32:24 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2011-04-04 16:52:39 (GMT)
commit66a7e4361f9f07962c7d22409aa6274da2dce9de (patch)
treed99c66e9e9563440ddbec11803ed2df8d13ecf5a
parent153bf90ea0fc5f58c27c82e13dc1c4d73b028f5e (diff)
downloadQt-66a7e4361f9f07962c7d22409aa6274da2dce9de.zip
Qt-66a7e4361f9f07962c7d22409aa6274da2dce9de.tar.gz
Qt-66a7e4361f9f07962c7d22409aa6274da2dce9de.tar.bz2
QStringList: constructor for std::initializer_list
Reviewed-by: Joao
-rw-r--r--src/corelib/tools/qstringlist.h3
-rw-r--r--tests/auto/qstringlist/tst_qstringlist.cpp13
2 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h
index a211430..a0290bc 100644
--- a/src/corelib/tools/qstringlist.h
+++ b/src/corelib/tools/qstringlist.h
@@ -70,6 +70,9 @@ public:
inline explicit QStringList(const QString &i) { append(i); }
inline QStringList(const QStringList &l) : QList<QString>(l) { }
inline QStringList(const QList<QString> &l) : QList<QString>(l) { }
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ inline QStringList(std::initializer_list<QString> args) : QList(args) { }
+#endif
inline void sort();
inline int removeDuplicates();
diff --git a/tests/auto/qstringlist/tst_qstringlist.cpp b/tests/auto/qstringlist/tst_qstringlist.cpp
index 283c17f..d8db00a 100644
--- a/tests/auto/qstringlist/tst_qstringlist.cpp
+++ b/tests/auto/qstringlist/tst_qstringlist.cpp
@@ -78,6 +78,8 @@ private slots:
void join() const;
void join_data() const;
void joinEmptiness() const;
+
+ void initializeList() const;
};
extern const char email[];
@@ -321,5 +323,16 @@ void tst_QStringList::joinEmptiness() const
QVERIFY(string.isNull());
}
+void tst_QStringList::initializeList() const
+{
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ QStringList v1{QLatin1String("hello"),"world",QString::fromLatin1("plop")};
+ QCOMPARE(v1, (QStringList() << "hello" << "world" << "plop"));
+ QCOMPARE(v1, (QStringList{"hello","world","plop"}));
+#else
+ QSKIP("Require C++0x support, pass the right flag to the compiler", SkipAll);
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QStringList)
#include "tst_qstringlist.moc"