Merge remote-tracking branch 'origin/master' into api_changes
[profile/ivi/qtbase.git] / src / corelib / tools / qpair.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QPAIR_H
43 #define QPAIR_H
44
45 #include <QtCore/qdatastream.h>
46
47 QT_BEGIN_HEADER
48
49 QT_BEGIN_NAMESPACE
50
51
52 template <class T1, class T2>
53 struct QPair
54 {
55     typedef T1 first_type;
56     typedef T2 second_type;
57
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!
61
62     T1 first;
63     T2 second;
64 };
65
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> >
70 {
71 public:
72     enum {
73         isComplex = QTypeInfo<T1>::isComplex || QTypeInfo<T2>::isComplex,
74         isStatic  = QTypeInfo<T1>::isStatic  || QTypeInfo<T2>::isStatic,
75         isLarge   = sizeof(QPair<T1, T2>) > sizeof(void*),
76         isPointer = false,
77         isDummy   = false,
78         sizeOf    = sizeof(QPair<T1, T2>)
79     };
80 };
81
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; }
85
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); }
89
90 template <class T1, class T2>
91 Q_INLINE_TEMPLATE bool operator<(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
92 {
93     return p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second);
94 }
95
96 template <class T1, class T2>
97 Q_INLINE_TEMPLATE bool operator>(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
98 {
99     return p2 < p1;
100 }
101
102 template <class T1, class T2>
103 Q_INLINE_TEMPLATE bool operator<=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
104 {
105     return !(p2 < p1);
106 }
107
108 template <class T1, class T2>
109 Q_INLINE_TEMPLATE bool operator>=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
110 {
111     return !(p1 < p2);
112 }
113
114 template <class T1, class T2>
115 Q_OUTOFLINE_TEMPLATE QPair<T1, T2> qMakePair(const T1 &x, const T2 &y)
116 {
117     return QPair<T1, T2>(x, y);
118 }
119
120 #ifndef QT_NO_DATASTREAM
121 template <class T1, class T2>
122 inline QDataStream& operator>>(QDataStream& s, QPair<T1, T2>& p)
123 {
124     s >> p.first >> p.second;
125     return s;
126 }
127
128 template <class T1, class T2>
129 inline QDataStream& operator<<(QDataStream& s, const QPair<T1, T2>& p)
130 {
131     s << p.first << p.second;
132     return s;
133 }
134 #endif
135
136 QT_END_NAMESPACE
137
138 QT_END_HEADER
139
140 #endif // QPAIR_H