generalized initializers and rvalue references are standard since C++11 [ci reset]

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-01-28 16:31:30 +02:00
parent da4f5e3f3b
commit 028f6d5f12
36 changed files with 10 additions and 127 deletions

View file

@ -180,13 +180,11 @@ struct PushBackWrapper
return c.push_back(u);
}
#ifdef Q_COMPILER_RVALUE_REFS
template <class C, class U>
inline void operator()(C &c, U &&u) const
{
return c.push_back(u);
}
#endif
};
template <typename Functor, bool foo = HasResultType<Functor>::Value>

View file

@ -77,43 +77,17 @@ QT_USE_NAMESPACE
GNU - GNU C++
CLANG - C++ front-end for the LLVM compiler
Should be sorted most to least authoritative.
Paper Macro SD-6 macro
N2672 Q_COMPILER_INITIALIZER_LISTS
N2118 N2844 N3053 Q_COMPILER_RVALUE_REFS __cpp_rvalue_references = 200610
For any future version of the C++ standard, we use only the SD-6 macro.
For full listing, see
http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
*/
#if defined(__GNUC__)
# define Q_CC_GNU
# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
/* C++0x features supported in GCC 4.3: */
# define Q_COMPILER_RVALUE_REFS
/* C++0x features supported in GCC 4.4: */
# define Q_COMPILER_INITIALIZER_LISTS
/* C++0x features supported in GCC 4.6: */
# ifdef __EXCEPTIONS
# define Q_COMPILER_EXCEPTIONS
# endif
# ifdef __EXCEPTIONS
# define Q_COMPILER_EXCEPTIONS
# endif
#elif defined(__clang__)
# define Q_CC_CLANG
# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
/* Detect C++ features using __has_feature(), see http://clang.llvm.org/docs/LanguageExtensions.html#cxx11 */
# if __has_feature(cxx_generalized_initializers)
# define Q_COMPILER_INITIALIZER_LISTS
# endif
# if __has_feature(cxx_rvalue_references)
# define Q_COMPILER_RVALUE_REFS
# endif
# if __has_feature(cxx_exceptions)
# define Q_COMPILER_EXCEPTIONS
# endif
# if __has_feature(cxx_exceptions)
# define Q_COMPILER_EXCEPTIONS
# endif
#else

View file

@ -86,10 +86,8 @@ public:
QDir &operator=(const QDir &);
QDir &operator=(const QString &path);
#ifdef Q_COMPILER_RVALUE_REFS
inline QDir &operator=(QDir &&other)
{ qSwap(d_ptr, other.d_ptr); return *this; }
#endif
void setPath(const QString &path);
QString path() const;

View file

@ -48,10 +48,8 @@ public:
~QFileInfo();
QFileInfo &operator=(const QFileInfo &fileinfo);
#ifdef Q_COMPILER_RVALUE_REFS
inline QFileInfo&operator=(QFileInfo &&other)
{ qSwap(d_ptr, other.d_ptr); return *this; }
#endif
bool operator==(const QFileInfo &fileinfo) const;
inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); }

View file

@ -67,13 +67,10 @@ public:
#ifndef QT_NO_URL_CAST_FROM_STRING
QUrl &operator =(const QString &url);
#endif
#ifdef Q_COMPILER_RVALUE_REFS
inline QUrl &operator=(QUrl &&other)
{ qSwap(d, other.d); return *this; }
#endif
~QUrl();
inline void swap(QUrl &other) { qSwap(d, other.d); }
~QUrl();
void setUrl(const QString &url, ParsingMode mode = TolerantMode);
void setEncodedUrl(const QByteArray &url, ParsingMode mode = TolerantMode);

View file

@ -188,11 +188,8 @@ class Q_CORE_EXPORT QVariant
#endif
QVariant& operator=(const QVariant &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QVariant &operator=(QVariant &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QVariant &other) { qSwap(d, other.d); }
Type type() const;

View file

@ -42,10 +42,8 @@ public:
explicit QBitArray(int size, bool val = false);
QBitArray(const QBitArray &other) : d(other.d) {}
inline QBitArray &operator=(const QBitArray &other) { d = other.d; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
inline QBitArray &operator=(QBitArray &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QBitArray &other) { qSwap(d, other.d); }

View file

@ -97,11 +97,8 @@ public:
QByteArray &operator=(const QByteArray &);
QByteArray &operator=(const char *str);
#ifdef Q_COMPILER_RVALUE_REFS
inline QByteArray &operator=(QByteArray &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QByteArray &other) { qSwap(d, other.d); }
inline int size() const;

View file

@ -76,10 +76,8 @@ public:
inline ~QContiguousCache() { if (!d) return; if (!d->ref.deref()) free(p); }
QContiguousCache<T> &operator=(const QContiguousCache<T> &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QContiguousCache<T> &operator=(QContiguousCache<T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QContiguousCache<T> &other) { qSwap(d, other.d); }
bool operator==(const QContiguousCache<T> &other) const;
inline bool operator!=(const QContiguousCache<T> &other) const { return !(*this == other); }

View file

@ -171,10 +171,8 @@ public:
inline ~QHash() { if (!d->ref.deref()) freeData(d); }
QHash<Key, T> &operator=(const QHash<Key, T> &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QHash<Key, T> &operator=(QHash<Key, T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QHash<Key, T> &other) { qSwap(d, other.d); }
bool operator==(const QHash<Key, T> &other) const;

View file

@ -60,10 +60,8 @@ public:
inline QLinkedList(const QLinkedList<T> &l) : d(l.d) { d->ref.ref(); }
~QLinkedList();
QLinkedList<T> &operator=(const QLinkedList<T> &);
#ifdef Q_COMPILER_RVALUE_REFS
inline QLinkedList<T> &operator=(QLinkedList<T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QLinkedList<T> &other) { qSwap(d, other.d); }
bool operator==(const QLinkedList<T> &l) const;
inline bool operator!=(const QLinkedList<T> &l) const { return !(*this == l); }

View file

@ -28,17 +28,12 @@
#include <iterator>
#include <list>
#ifdef Q_COMPILER_INITIALIZER_LISTS
#include <initializer_list>
#endif
#include <new>
#include <string.h>
QT_BEGIN_NAMESPACE
template <typename T> class QVector;
template <typename T> class QSet;
@ -87,15 +82,11 @@ public:
inline QList(const QList<T> &l) : d(l.d) { d->ref.ref(); }
~QList();
QList<T> &operator=(const QList<T> &l);
#ifdef Q_COMPILER_RVALUE_REFS
inline QList &operator=(QList &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QList<T> &other) { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QList(std::initializer_list<T> args) : d(&QListData::shared_null)
{ d->ref.ref(); qCopy(args.begin(), args.end(), std::back_inserter(*this)); }
#endif
bool operator==(const QList<T> &l) const;
inline bool operator!=(const QList<T> &l) const { return !(*this == l); }
@ -686,5 +677,4 @@ Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List)
QT_END_NAMESPACE
#endif // QLIST_H

View file

@ -147,10 +147,8 @@ public:
inline ~QMap() { if (!d->ref.deref()) freeData(d); }
QMap<Key, T> &operator=(const QMap<Key, T> &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QMap<Key, T> &operator=(QMap<Key, T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QMap<Key, T> &other) { qSwap(d, other.d); }
explicit QMap(const typename std::map<Key, T> &other);
std::map<Key, T> toStdMap() const;

View file

@ -56,10 +56,8 @@ public:
QRegExp(const QRegExp &rx);
~QRegExp();
QRegExp &operator=(const QRegExp &rx);
#ifdef Q_COMPILER_RVALUE_REFS
inline QRegExp &operator=(QRegExp &&other)
{ qSwap(priv,other.priv); return *this; }
#endif
inline void swap(QRegExp &other) { qSwap(priv, other.priv); }
bool operator==(const QRegExp &rx) const;

View file

@ -39,10 +39,8 @@ public:
inline QSet<T> &operator=(const QSet<T> &other)
{ q_hash = other.q_hash; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
inline QSet<T> &operator=(QSet<T> &&other)
{ qSwap(q_hash, other.q_hash); return *this; }
#endif
inline void swap(QSet<T> &other) { q_hash.swap(other.q_hash); }
inline bool operator==(const QSet<T> &other) const

View file

@ -87,11 +87,9 @@ public:
}
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
QSharedDataPointer(QSharedDataPointer &&o) : d(o.d) { o.d = nullptr; }
inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline bool operator!() const { return !d; }
@ -171,11 +169,9 @@ public:
}
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) : d(o.d) { o.d = nullptr; }
inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline bool operator!() const { return !d; }

View file

@ -410,13 +410,11 @@ public:
BaseClass::internalCopy(other);
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
inline QSharedPointer<T> &operator=(QSharedPointer<T> &&other)
{
QSharedPointer<T>::internalSwap(other);
return *this;
}
#endif
template <class X>
inline QSharedPointer(const QSharedPointer<X> &other) : BaseClass(other)

View file

@ -49,9 +49,7 @@ public:
QStdVector() : Data() { }
explicit QStdVector(int size) : Data(size) { }
QStdVector(int size, const T &t) : Data() { Data::reserve(size); Data::insert(Data::begin(), size, t);}
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QStdVector(std::initializer_list<T> args) : Data(args) { }
#endif
inline bool isEmpty() const { return Data::empty(); }
inline void squeeze() { Data::shrink_to_fit(); }

View file

@ -55,11 +55,10 @@ public:
QString &operator=(QChar c);
QString &operator=(const QString &);
inline QString &operator=(const QLatin1String &);
#ifdef Q_COMPILER_RVALUE_REFS
inline QString &operator=(QString &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QString &other) { qSwap(d, other.d); }
inline int size() const { return d->size; }
inline int count() const { return d->size; }
inline int length() const;

View file

@ -39,9 +39,7 @@ 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<QString>(args) { }
#endif
void sort();
int removeDuplicates();

View file

@ -70,14 +70,11 @@ public:
inline QVector(const QVector<T> &v) : d(v.d) { d->ref.ref(); }
inline ~QVector() { if (!d->ref.deref()) freeData(p); }
QVector<T> &operator=(const QVector<T> &v);
#ifdef Q_COMPILER_RVALUE_REFS
inline QVector<T> operator=(QVector<T> &&other)
{ qSwap(p, other.p); return *this; }
#endif
inline void swap(QVector<T> &other) { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QVector(std::initializer_list<T> args);
#endif
bool operator==(const QVector<T> &v) const;
inline bool operator!=(const QVector<T> &v) const { return !(*this == v); }
@ -365,7 +362,6 @@ QVector<T>::QVector(int asize, const T &t)
new (--i) T(t);
}
#ifdef Q_COMPILER_INITIALIZER_LISTS
template <typename T>
QVector<T>::QVector(std::initializer_list<T> args)
{
@ -378,7 +374,6 @@ QVector<T>::QVector(std::initializer_list<T> args)
while (i != p->array)
new (--i) T(*(--it));
}
#endif
template <typename T>
void QVector<T>::freeData(Data *x)

View file

@ -26,11 +26,7 @@
#include <QtCore/qshareddata.h>
#include <QtCore/qmetatype.h>
#ifdef Q_COMPILER_RVALUE_REFS
# include <utility>
#endif
#include <utility>
QT_BEGIN_NAMESPACE
@ -55,12 +51,10 @@ public:
void giveFileDescriptor(int fileDescriptor);
int takeFileDescriptor();
#if defined(Q_COMPILER_RVALUE_REFS)
QDBusUnixFileDescriptor(QDBusUnixFileDescriptor &&other) : d(static_cast<Data &&>(other.d))
{ }
inline QDBusUnixFileDescriptor &operator=(QDBusUnixFileDescriptor &&other)
{ d.swap(other.d); return *this; }
#endif
protected:
typedef QExplicitlySharedDataPointer<QDBusUnixFileDescriptorPrivate> Data;

View file

@ -46,10 +46,8 @@ public:
explicit QIcon(QIconEngine *engine);
~QIcon();
QIcon &operator=(const QIcon &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QIcon &operator=(QIcon &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QIcon &other) { qSwap(d, other.d); }
operator QVariant() const;

View file

@ -75,10 +75,8 @@ public:
~QImage();
QImage &operator=(const QImage &);
#ifdef Q_COMPILER_RVALUE_REFS
inline QImage &operator=(QImage &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QImage &other) { qSwap(d, other.d); }
bool isNull() const;

View file

@ -57,10 +57,8 @@ public:
~QPixmap();
QPixmap &operator=(const QPixmap &);
#ifdef Q_COMPILER_RVALUE_REFS
inline QPixmap &operator=(QPixmap &&other)
{ qSwap(data, other.data); return *this; }
#endif
inline void swap(QPixmap &other) { qSwap(data, other.data); }
operator QVariant() const;

View file

@ -59,10 +59,8 @@ public:
QCursor(const QCursor &cursor);
~QCursor();
QCursor &operator=(const QCursor &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QCursor &operator=(QCursor &&other)
{ qSwap(d, other.d); return *this; }
#endif
operator QVariant() const;
Qt::CursorShape shape() const;

View file

@ -50,14 +50,12 @@ public:
QPalette(const QPalette &palette);
~QPalette();
QPalette &operator=(const QPalette &palette);
#ifdef Q_COMPILER_RVALUE_REFS
inline QPalette &operator=(QPalette &&other)
{
resolve_mask = other.resolve_mask;
current_group = other.current_group;
qSwap(d, other.d); return *this;
}
#endif
operator QVariant() const;
// Do not change the order, the serialization format depends on it

View file

@ -58,10 +58,8 @@ public:
~QBrush();
QBrush &operator=(const QBrush &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QBrush &operator=(QBrush &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QBrush &other) { qSwap(d, other.d); }
operator QVariant() const;

View file

@ -71,10 +71,8 @@ public:
explicit QPainterPath(const QPointF &startPoint);
QPainterPath(const QPainterPath &other);
QPainterPath &operator=(const QPainterPath &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QPainterPath &operator=(QPainterPath &&other)
{ qSwap(d_ptr, other.d_ptr); return *this; }
#endif
~QPainterPath();
inline void swap(QPainterPath &other) { d_ptr.swap(other.d_ptr); }

View file

@ -45,10 +45,8 @@ public:
~QPen();
QPen &operator=(const QPen &pen);
#ifdef Q_COMPILER_RVALUE_REFS
inline QPen &operator=(QPen &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QPen &other) { qSwap(d, other.d); }
Qt::PenStyle style() const;

View file

@ -55,11 +55,10 @@ public:
QRegion(const QBitmap &bitmap);
~QRegion();
QRegion &operator=(const QRegion &);
#ifdef Q_COMPILER_RVALUE_REFS
inline QRegion &operator=(QRegion &&other)
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QRegion &other) { qSwap(d, other.d); }
bool isEmpty() const;
bool contains(const QPoint &p) const;

View file

@ -152,10 +152,8 @@ public:
bool operator<(const QFont &) const;
operator QVariant() const;
bool isCopyOf(const QFont &) const;
#ifdef Q_COMPILER_RVALUE_REFS
inline QFont &operator=(QFont &&other)
{ qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); return *this; }
#endif
Qt::HANDLE handle() const;
#if defined(Q_WS_X11)

View file

@ -40,10 +40,8 @@ public:
~QFontMetrics();
QFontMetrics &operator=(const QFontMetrics &);
#ifdef Q_COMPILER_RVALUE_REFS
inline QFontMetrics &operator=(QFontMetrics &&other)
{ qSwap(d, other.d); return *this; }
#endif
int ascent() const;
int descent() const;
@ -95,10 +93,9 @@ public:
QFontMetricsF &operator=(const QFontMetricsF &);
QFontMetricsF &operator=(const QFontMetrics &);
#ifdef Q_COMPILER_RVALUE_REFS
inline QFontMetricsF &operator=(QFontMetricsF &&other)
{ qSwap(d, other.d); return *this; }
#endif
qreal ascent() const;
qreal descent() const;
qreal height() const;

View file

@ -657,7 +657,6 @@ void tst_QList::testSTLIterators() const
void tst_QList::initializeList() const
{
#ifdef Q_COMPILER_INITIALIZER_LISTS
QList<int> v1{2,3,4};
QCOMPARE(v1, QList<int>() << 2 << 3 << 4);
QCOMPARE(v1, (QList<int>{2,3,4}));
@ -666,7 +665,6 @@ void tst_QList::initializeList() const
QList<QList<int>> v3;
v3 << v1 << (QList<int>() << 1) << QList<int>() << v1;
QCOMPARE(v3, v2);
#endif
}
QTEST_APPLESS_MAIN(tst_QList)

View file

@ -301,13 +301,9 @@ void tst_QStringList::joinEmptiness() const
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)

View file

@ -829,7 +829,6 @@ void tst_QVector::QTBUG6416_reserve()
void tst_QVector::initializeList()
{
#ifdef Q_COMPILER_INITIALIZER_LISTS
QVector<int> v1{2,3,4};
QCOMPARE(v1, QVector<int>() << 2 << 3 << 4);
QCOMPARE(v1, (QVector<int>{2,3,4}));
@ -838,7 +837,6 @@ void tst_QVector::initializeList()
QVector<QVector<int>> v3;
v3 << v1 << (QVector<int>() << 1) << QVector<int>() << v1;
QCOMPARE(v3, v2);
#endif
}
QTEST_APPLESS_MAIN(tst_QVector)