From 8aff3d0bed78c64496178480af0545ec206e9938 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 28 Apr 2013 21:23:53 -0700 Subject: [PATCH] Add a pair of constructor/assignment function pairs to QPair To allow copying one QPair of two types to a QPair of two different types. Change-Id: Ie7aa84cf5a361be6b7d242517578172c35bcacfd Reviewed-by: Olivier Goffart --- src/corelib/tools/qpair.h | 13 +++++++++++++ src/corelib/tools/qpair.qdoc | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h index 96b1b65e33..9b8691a3d8 100644 --- a/src/corelib/tools/qpair.h +++ b/src/corelib/tools/qpair.h @@ -57,6 +57,19 @@ struct QPair QPair(const T1 &t1, const T2 &t2) : first(t1), second(t2) {} // compiler-generated copy/move ctor/assignment operators are fine! + template + QPair(const QPair &p) : first(p.first), second(p.second) {} + template + QPair &operator=(const QPair &p) + { first = p.first; second = p.second; return *this; } +#ifdef Q_COMPILER_RVALUE_REFS + template + QPair(QPair &&p) : first(std::move(p.first)), second(std::move(p.second)) {} + template + QPair &operator=(QPair &&p) + { first = std::move(p.first); second = std::move(p.second); return *this; } +#endif + T1 first; T2 second; }; diff --git a/src/corelib/tools/qpair.qdoc b/src/corelib/tools/qpair.qdoc index b0caf1aaf0..dd3df8c464 100644 --- a/src/corelib/tools/qpair.qdoc +++ b/src/corelib/tools/qpair.qdoc @@ -96,6 +96,26 @@ \sa qMakePair() */ +/*! + \fn QPair::QPair(const QPair &p) + \since 5.2 + + Constructs a pair from the other pair \a p, of types TT1 and TT2. This + constructor will fail if \c first cannot be initialized from \c p.first or + if \c second cannot be initialized from \c p.second. + + \sa qMakePair() +*/ + +/*! + \fn QPair &QPair::operator=(const QPair &p) + \since 5.2 + + Copies the pair \a p onto this pair. + + \sa qMakePair() +*/ + /*! \fn bool operator==(const QPair &p1, const QPair &p2) \relates QPair