stlab.adobe.com Adobe Systems Incorporated
pair.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_UTILITY_PAIR_HPP
10 #define ADOBE_UTILITY_PAIR_HPP
11 
12 /*************************************************************************************************/
13 
14 #include <adobe/config.hpp>
15 
16 #include <utility>
17 
18 #include <boost/operators.hpp>
19 
20 #include <adobe/empty.hpp>
21 #include <adobe/move.hpp>
22 
23 #include <adobe/implementation/swap.hpp>
24 
25 /*************************************************************************************************/
26 
27 namespace adobe {
28 
29 /*************************************************************************************************/
30 
36 template <typename T1, typename T2 = T1>
39 {
40  typedef T1 first_type;
41  typedef T2 second_type;
42 
43  T1 first;
44  T2 second;
45 
46  friend inline bool operator==(const aggregate_pair& x, const aggregate_pair&y)
47  { return x.first == y.first && x.second == y.second; }
48 
49  friend inline bool operator<(const aggregate_pair& x, const aggregate_pair& y)
50  { return x.first < y.first || (!(y.first < x.first) && x.second < y.second); }
51 
52  friend inline bool operator!=(const aggregate_pair& x, const aggregate_pair&y)
53  { return !(x == y); }
54 
55  friend inline bool operator>(const aggregate_pair& x, const aggregate_pair& y)
56  { return y < x; }
57 
58  friend inline bool operator<=(const aggregate_pair& x, const aggregate_pair& y)
59  { return !(y < x); }
60 
61  friend inline bool operator>=(const aggregate_pair& x, const aggregate_pair& y)
62  { return !(x < y); }
63 
64  friend inline void swap(aggregate_pair& x, aggregate_pair& y)
65  { swap(x.first, y.first); swap(x.second, y.second); }
66 };
67 
68 /*************************************************************************************************/
69 
71 template <typename T1, typename T2 = T1>
72 struct pair : boost::totally_ordered<pair<T1, T2>, pair<T1, T2>, empty_base<pair<T1, T2> > >
73 {
74  typedef T1 first_type;
75  typedef T2 second_type;
76 
77  T1 first;
78  T2 second;
79 
80  pair() : first(), second() { }
81 
82  pair(move_from<pair> x) : first(adobe::move(x.source.first)), second(adobe::move(x.source.second)) { }
83 
84  pair& operator=(pair x) { first = adobe::move(x.first); second = adobe::move(x.second); return *this; }
85 
86  pair(T1 x, T2 y) : first(adobe::move(x)), second(adobe::move(y)) { }
87 
88  template <typename U1, typename U2>
89  pair(const pair<U1, U2>& p) : first(p.first), second(p.second) { }
90 
91  template <typename U1, typename U2>
92  pair(const std::pair<U1, U2>& p) : first(p.first), second(p.second) { }
93 
94  template <typename U1, typename U2>
95  pair(const aggregate_pair<U1, U2>& p) : first(p.first), second(p.second) { }
96 
97  friend inline bool operator==(const pair& x, const pair&y)
98  { return x.first == y.first && x.second == y.second; }
99 
100  friend inline bool operator<(const pair& x, const pair& y)
101  { return x.first < y.first || (!(y.first < x.first) && x.second < y.second); }
102 
103  friend inline void swap(pair& x, pair& y)
104  { swap(x.first, y.first); swap(x.second, y.second); }
105 };
106 
108 template <typename T1, typename T2>
109 inline pair<T1, T2> make_pair(T1 x, T2 y)
110 { return pair<T1, T2>(adobe::move(x), adobe::move(y)); }
111 
112 /*************************************************************************************************/
113 
114 } // namespace adobe
115 
116 /*************************************************************************************************/
117 
118 // ADOBE_UTILITY_PAIR_HPP
119 #endif
120 
121 /*************************************************************************************************/
T2 second_type
Definition: pair.hpp:75
friend void swap(pair &x, pair &y)
Definition: pair.hpp:103
pair(const pair< U1, U2 > &p)
Definition: pair.hpp:89
T1 first
Definition: pair.hpp:77
pair(move_from< pair > x)
Definition: pair.hpp:82
move_from is used for move_ctors.
Definition: move.hpp:306
friend bool operator<(const aggregate_pair &x, const aggregate_pair &y)
Definition: pair.hpp:49
friend void swap(aggregate_pair &x, aggregate_pair &y)
Definition: pair.hpp:64
friend bool operator<(const pair &x, const pair &y)
Definition: pair.hpp:100
T2 second
Definition: pair.hpp:78
friend bool operator<=(const aggregate_pair &x, const aggregate_pair &y)
Definition: pair.hpp:58
friend bool operator!=(const aggregate_pair &x, const aggregate_pair &y)
Definition: pair.hpp:52
pair & operator=(pair x)
Definition: pair.hpp:84
T1 first_type
Definition: pair.hpp:74
friend bool operator==(const pair &x, const pair &y)
Definition: pair.hpp:97
pair(const aggregate_pair< U1, U2 > &p)
Definition: pair.hpp:95
friend bool operator>=(const aggregate_pair &x, const aggregate_pair &y)
Definition: pair.hpp:61
pair(T1 x, T2 y)
Definition: pair.hpp:86
friend bool operator==(const aggregate_pair &x, const aggregate_pair &y)
Definition: pair.hpp:46
friend bool operator>(const aggregate_pair &x, const aggregate_pair &y)
Definition: pair.hpp:55
pair< T1, T2 > make_pair(T1 x, T2 y)
Definition: pair.hpp:109
pair(const std::pair< U1, U2 > &p)
Definition: pair.hpp:92

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google