1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qdatastream.h>
52 template <class T1, class T2>
55 typedef T1 first_type;
56 typedef T2 second_type;
58 QPair() : first(), second() {}
59 QPair(const T1 &t1, const T2 &t2) : first(t1), second(t2) {}
60 // compiler-generated copy/move ctor/assignment operators are fine!
66 // mark QPair<T1,T2> as complex/movable/primitive depending on the
67 // typeinfos of the constituents:
68 template<class T1, class T2>
69 class QTypeInfo< QPair<T1, T2> >
73 isComplex = QTypeInfo<T1>::isComplex || QTypeInfo<T2>::isComplex,
74 isStatic = QTypeInfo<T1>::isStatic || QTypeInfo<T2>::isStatic,
75 isLarge = sizeof(QPair<T1, T2>) > sizeof(void*),
78 sizeOf = sizeof(QPair<T1, T2>)
82 template <class T1, class T2>
83 Q_INLINE_TEMPLATE bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
84 { return p1.first == p2.first && p1.second == p2.second; }
86 template <class T1, class T2>
87 Q_INLINE_TEMPLATE bool operator!=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
88 { return !(p1 == p2); }
90 template <class T1, class T2>
91 Q_INLINE_TEMPLATE bool operator<(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
93 return p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second);
96 template <class T1, class T2>
97 Q_INLINE_TEMPLATE bool operator>(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
102 template <class T1, class T2>
103 Q_INLINE_TEMPLATE bool operator<=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
108 template <class T1, class T2>
109 Q_INLINE_TEMPLATE bool operator>=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
114 template <class T1, class T2>
115 Q_OUTOFLINE_TEMPLATE QPair<T1, T2> qMakePair(const T1 &x, const T2 &y)
117 return QPair<T1, T2>(x, y);
120 #ifndef QT_NO_DATASTREAM
121 template <class T1, class T2>
122 inline QDataStream& operator>>(QDataStream& s, QPair<T1, T2>& p)
124 s >> p.first >> p.second;
128 template <class T1, class T2>
129 inline QDataStream& operator<<(QDataStream& s, const QPair<T1, T2>& p)
131 s << p.first << p.second;