00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef _STL_PAIR_H
00058 #define _STL_PAIR_H 1
00059
00060 #include <bits/move.h>
00061
00062 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00063 #include <type_traits>
00064 #endif
00065
00066 _GLIBCXX_BEGIN_NAMESPACE(std)
00067
00068 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00069 struct piecewise_construct_t { };
00070
00071 static const piecewise_construct_t piecewise_construct
00072 = piecewise_construct_t();
00073
00074
00075 template<typename...>
00076 class tuple;
00077
00078 template<int...>
00079 struct _Index_tuple;
00080 #endif
00081
00082
00083 template<class _T1, class _T2>
00084 struct pair
00085 {
00086 typedef _T1 first_type;
00087 typedef _T2 second_type;
00088
00089 _T1 first;
00090 _T2 second;
00091
00092
00093
00094
00095
00096 pair()
00097 : first(), second() { }
00098
00099
00100 pair(const _T1& __a, const _T2& __b)
00101 : first(__a), second(__b) { }
00102
00103 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00104 pair(const pair&) = default;
00105
00106
00107 template<class _U1, class = typename
00108 std::enable_if<std::is_convertible<_U1, _T1>::value>::type>
00109 pair(_U1&& __x, const _T2& __y)
00110 : first(std::forward<_U1>(__x)),
00111 second(__y) { }
00112
00113 template<class _U2, class = typename
00114 std::enable_if<std::is_convertible<_U2, _T2>::value>::type>
00115 pair(const _T1& __x, _U2&& __y)
00116 : first(__x),
00117 second(std::forward<_U2>(__y)) { }
00118
00119 template<class _U1, class _U2, class = typename
00120 std::enable_if<std::is_convertible<_U1, _T1>::value
00121 && std::is_convertible<_U2, _T2>::value>::type>
00122 pair(_U1&& __x, _U2&& __y)
00123 : first(std::forward<_U1>(__x)),
00124 second(std::forward<_U2>(__y)) { }
00125
00126 template<class... _Args1, class... _Args2>
00127 pair(piecewise_construct_t,
00128 tuple<_Args1...> __first_args,
00129 tuple<_Args2...> __second_args)
00130 : first(__cons<first_type>(std::move(__first_args))),
00131 second(__cons<second_type>(std::move(__second_args))) { }
00132 #endif
00133
00134
00135 template<class _U1, class _U2>
00136 pair(const pair<_U1, _U2>& __p)
00137 : first(__p.first),
00138 second(__p.second) { }
00139
00140 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00141 template<class _U1, class _U2>
00142 pair(pair<_U1, _U2>&& __p)
00143 : first(std::forward<_U1>(__p.first)),
00144 second(std::forward<_U2>(__p.second)) { }
00145
00146 pair&
00147 operator=(pair&& __p)
00148 {
00149 first = std::move(__p.first);
00150 second = std::move(__p.second);
00151 return *this;
00152 }
00153
00154 template<class _U1, class _U2>
00155 pair&
00156 operator=(const pair<_U1, _U2>& __p)
00157 {
00158 first = __p.first;
00159 second = __p.second;
00160 return *this;
00161 }
00162
00163 template<class _U1, class _U2>
00164 pair&
00165 operator=(pair<_U1, _U2>&& __p)
00166 {
00167 first = std::move(__p.first);
00168 second = std::move(__p.second);
00169 return *this;
00170 }
00171
00172 void
00173 swap(pair& __p)
00174 {
00175 using std::swap;
00176 swap(first, __p.first);
00177 swap(second, __p.second);
00178 }
00179
00180 private:
00181 template<typename _Tp, typename... _Args>
00182 static _Tp
00183 __cons(tuple<_Args...>&&);
00184
00185 template<typename _Tp, typename... _Args, int... _Indexes>
00186 static _Tp
00187 __do_cons(tuple<_Args...>&&, const _Index_tuple<_Indexes...>&);
00188 #endif
00189 };
00190
00191
00192 template<class _T1, class _T2>
00193 inline bool
00194 operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00195 { return __x.first == __y.first && __x.second == __y.second; }
00196
00197
00198 template<class _T1, class _T2>
00199 inline bool
00200 operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00201 { return __x.first < __y.first
00202 || (!(__y.first < __x.first) && __x.second < __y.second); }
00203
00204
00205 template<class _T1, class _T2>
00206 inline bool
00207 operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00208 { return !(__x == __y); }
00209
00210
00211 template<class _T1, class _T2>
00212 inline bool
00213 operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00214 { return __y < __x; }
00215
00216
00217 template<class _T1, class _T2>
00218 inline bool
00219 operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00220 { return !(__y < __x); }
00221
00222
00223 template<class _T1, class _T2>
00224 inline bool
00225 operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00226 { return !(__x < __y); }
00227
00228 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00229
00230
00231
00232 template<class _T1, class _T2>
00233 inline void
00234 swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
00235 { __x.swap(__y); }
00236 #endif
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 #ifndef __GXX_EXPERIMENTAL_CXX0X__
00251 template<class _T1, class _T2>
00252 inline pair<_T1, _T2>
00253 make_pair(_T1 __x, _T2 __y)
00254 { return pair<_T1, _T2>(__x, __y); }
00255 #else
00256
00257 template<class _T1, class _T2>
00258 inline pair<typename __decay_and_strip<_T1>::__type,
00259 typename __decay_and_strip<_T2>::__type>
00260 make_pair(_T1&& __x, _T2&& __y)
00261 {
00262 return pair<typename __decay_and_strip<_T1>::__type,
00263 typename __decay_and_strip<_T2>::__type>
00264 (std::forward<_T1>(__x), std::forward<_T2>(__y));
00265 }
00266 #endif
00267
00268 _GLIBCXX_END_NAMESPACE
00269
00270 #endif