pair.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2005-2007 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /*************************************************************************************************/ 00008 00009 #ifndef ADOBE_UTILITY_PAIR_HPP 00010 #define ADOBE_UTILITY_PAIR_HPP 00011 00012 /*************************************************************************************************/ 00013 00014 #include <adobe/config.hpp> 00015 00016 #include <utility> 00017 00018 #include <boost/operators.hpp> 00019 00020 #include <adobe/empty.hpp> 00021 #include <adobe/move.hpp> 00022 00023 #include <adobe/implementation/swap.hpp> 00024 00025 /*************************************************************************************************/ 00026 00027 namespace adobe { 00028 00029 /*************************************************************************************************/ 00030 00036 00037 template <typename T1, typename T2 = T1> 00038 struct aggregate_pair 00039 { 00040 typedef T1 first_type; 00041 typedef T2 second_type; 00042 00043 T1 first; 00044 T2 second; 00045 00046 friend inline bool operator==(const aggregate_pair& x, const aggregate_pair&y) 00047 { return x.first == y.first && x.second == y.second; } 00048 00049 friend inline bool operator<(const aggregate_pair& x, const aggregate_pair& y) 00050 { return x.first < y.first || (!(y.first < x.first) && x.second < y.second); } 00051 00052 friend inline bool operator!=(const aggregate_pair& x, const aggregate_pair&y) 00053 { return !(x == y); } 00054 00055 friend inline bool operator>(const aggregate_pair& x, const aggregate_pair& y) 00056 { return y < x; } 00057 00058 friend inline bool operator<=(const aggregate_pair& x, const aggregate_pair& y) 00059 { return !(y < x); } 00060 00061 friend inline bool operator>=(const aggregate_pair& x, const aggregate_pair& y) 00062 { return !(x < y); } 00063 00064 friend inline void swap(aggregate_pair& x, aggregate_pair& y) 00065 { swap(x.first, y.first); swap(x.second, y.second); } 00066 }; 00067 00068 /*************************************************************************************************/ 00069 00071 template <typename T1, typename T2 = T1> 00072 struct pair : boost::totally_ordered<pair<T1, T2>, pair<T1, T2>, empty_base<pair<T1, T2> > > 00073 { 00074 typedef T1 first_type; 00075 typedef T2 second_type; 00076 00077 T1 first; 00078 T2 second; 00079 00080 pair() : first(), second() { } 00081 00082 pair(move_from<pair> x) : first(adobe::move(x.source.first)), second(adobe::move(x.source.second)) { } 00083 00084 pair& operator=(pair x) { first = adobe::move(x.first); second = adobe::move(x.second); return *this; } 00085 00086 pair(T1 x, T2 y) : first(adobe::move(x)), second(adobe::move(y)) { } 00087 00088 template <typename U1, typename U2> 00089 pair(const pair<U1, U2>& p) : first(p.first), second(p.second) { } 00090 00091 template <typename U1, typename U2> 00092 pair(const std::pair<U1, U2>& p) : first(p.first), second(p.second) { } 00093 00094 template <typename U1, typename U2> 00095 pair(const aggregate_pair<U1, U2>& p) : first(p.first), second(p.second) { } 00096 00097 friend inline bool operator==(const pair& x, const pair&y) 00098 { return x.first == y.first && x.second == y.second; } 00099 00100 friend inline bool operator<(const pair& x, const pair& y) 00101 { return x.first < y.first || (!(y.first < x.first) && x.second < y.second); } 00102 00103 friend inline void swap(pair& x, pair& y) 00104 { swap(x.first, y.first); swap(x.second, y.second); } 00105 }; 00106 00108 template <typename T1, typename T2> 00109 inline pair<T1, T2> make_pair(T1 x, T2 y) 00110 { return pair<T1, T2>(adobe::move(x), adobe::move(y)); } 00111 00112 /*************************************************************************************************/ 00113 00114 } // namespace adobe 00115 00116 /*************************************************************************************************/ 00117 00118 // ADOBE_UTILITY_PAIR_HPP 00119 #endif 00120 00121 /*************************************************************************************************/ |