source: trunk/include/qpair.h@ 81

Last change on this file since 81 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/****************************************************************************
2**
3** Definition of QPair class
4**
5**
6** Copyright (C) 1992-2001 Trolltech AS. All rights reserved.
7**
8** This file is part of the tools module of the Qt GUI Toolkit.
9**
10** This file may be distributed under the terms of the Q Public License
11** as defined by Trolltech AS of Norway and appearing in the file
12** LICENSE.QPL included in the packaging of this file.
13**
14** This file may be distributed and/or modified under the terms of the
15** GNU General Public License version 2 as published by the Free Software
16** Foundation and appearing in the file LICENSE.GPL included in the
17** packaging of this file.
18**
19** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
20** licenses may use this file in accordance with the Qt Commercial License
21** Agreement provided with the Software.
22**
23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25**
26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
27** information about Qt Commercial License Agreements.
28** See http://www.trolltech.com/qpl/ for QPL licensing information.
29** See http://www.trolltech.com/gpl/ for GPL licensing information.
30**
31** Contact info@trolltech.com if any conditions of this licensing are
32** not clear to you.
33**
34**********************************************************************/
35
36#ifndef QPAIR_H
37#define QPAIR_H
38
39#ifndef QT_H
40#include "qglobal.h"
41#include "qdatastream.h"
42#endif // QT_H
43
44template <class T1, class T2>
45struct QPair
46{
47 typedef T1 first_type;
48 typedef T2 second_type;
49
50 QPair()
51 : first( T1() ), second( T2() )
52 {}
53 QPair( const T1& t1, const T2& t2 )
54 : first( t1 ), second( t2 )
55 {}
56
57 QPair<T1, T2>& operator=(const QPair<T1, T2>& other)
58 {
59 if (this != &other) {
60 first = other.first;
61 second = other.second;
62 }
63 return *this;
64 }
65
66 T1 first;
67 T2 second;
68};
69
70template <class T1, class T2>
71Q_INLINE_TEMPLATES bool operator==( const QPair<T1, T2>& x, const QPair<T1, T2>& y )
72{
73 return x.first == y.first && x.second == y.second;
74}
75
76template <class T1, class T2>
77Q_INLINE_TEMPLATES bool operator<( const QPair<T1, T2>& x, const QPair<T1, T2>& y )
78{
79 return x.first < y.first ||
80 ( !( y.first < x.first ) && x.second < y.second );
81}
82
83template <class T1, class T2>
84Q_INLINE_TEMPLATES QPair<T1, T2> qMakePair( const T1& x, const T2& y )
85{
86 return QPair<T1, T2>( x, y );
87}
88
89#ifndef QT_NO_DATASTREAM
90template <class T1, class T2>
91inline QDataStream& operator>>( QDataStream& s, QPair<T1, T2>& p )
92{
93 s >> p.first >> p.second;
94 return s;
95}
96
97template <class T1, class T2>
98inline QDataStream& operator<<( QDataStream& s, const QPair<T1, T2>& p )
99{
100 s << p.first << p.second;
101 return s;
102}
103#endif
104
105#endif
Note: See TracBrowser for help on using the repository browser.