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 <ogoffart@woboq.com>
This commit is contained in:
Thiago Macieira 2013-04-28 21:23:53 -07:00 committed by The Qt Project
parent 620f788f86
commit 8aff3d0bed
2 changed files with 33 additions and 0 deletions

View File

@ -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 <typename TT1, typename TT2>
QPair(const QPair<TT1, TT2> &p) : first(p.first), second(p.second) {}
template <typename TT1, typename TT2>
QPair &operator=(const QPair<TT1, TT2> &p)
{ first = p.first; second = p.second; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
template <typename TT1, typename TT2>
QPair(QPair<TT1, TT2> &&p) : first(std::move(p.first)), second(std::move(p.second)) {}
template <typename TT1, typename TT2>
QPair &operator=(QPair<TT1, TT2> &&p)
{ first = std::move(p.first); second = std::move(p.second); return *this; }
#endif
T1 first;
T2 second;
};

View File

@ -96,6 +96,26 @@
\sa qMakePair()
*/
/*!
\fn QPair::QPair(const QPair<TT1, TT2> &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<TT1, TT2> &p)
\since 5.2
Copies the pair \a p onto this pair.
\sa qMakePair()
*/
/*! \fn bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
\relates QPair