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
00072 template<typename...>
00073 class tuple;
00074
00075 template<int...>
00076 struct _Index_tuple;
00077 #endif
00078
00079
00080 template<class _T1, class _T2>
00081 struct pair
00082 {
00083 typedef _T1 first_type;
00084 typedef _T2 second_type;
00085
00086 _T1 first;
00087 _T2 second;
00088
00089
00090
00091
00092
00093 pair()
00094 : first(), second() { }
00095
00096
00097 pair(const _T1& __a, const _T2& __b)
00098 : first(__a), second(__b) { }
00099
00100 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00101 pair(const pair&) = default;
00102
00103
00104 template<class _U1, class = typename
00105 std::enable_if<std::is_convertible<_U1, _T1>::value>::type>
00106 pair(_U1&& __x, const _T2& __y)
00107 : first(std::forward<_U1>(__x)),
00108 second(__y) { }
00109
00110 template<class _U2, class = typename
00111 std::enable_if<std::is_convertible<_U2, _T2>::value>::type>
00112 pair(const _T1& __x, _U2&& __y)
00113 : first(__x),
00114 second(std::forward<_U2>(__y)) { }
00115
00116 template<class _U1, class _U2, class = typename
00117 std::enable_if<std::is_convertible<_U1, _T1>::value
00118 && std::is_convertible<_U2, _T2>::value>::type>
00119 pair(_U1&& __x, _U2&& __y)
00120 : first(std::forward<_U1>(__x)),
00121 second(std::forward<_U2>(__y)) { }
00122
00123 template<class... _Args1, class... _Args2>
00124 pair(piecewise_construct_t,
00125 tuple<_Args1...> __first_args,
00126 tuple<_Args2...> __second_args)
00127 : first(__cons<first_type>(std::move(__first_args))),
00128 second(__cons<second_type>(std::move(__second_args))) { }
00129 #endif
00130
00131
00132 template<class _U1, class _U2>
00133 pair(const pair<_U1, _U2>& __p)
00134 : first(__p.first),
00135 second(__p.second) { }
00136
00137 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00138 template<class _U1, class _U2>
00139 pair(pair<_U1, _U2>&& __p)
00140 : first(std::forward<_U1>(__p.first)),
00141 second(std::forward<_U2>(__p.second)) { }
00142
00143 pair&
00144 operator=(pair&& __p)
00145 {
00146 first = std::move(__p.first);
00147 second = std::move(__p.second);
00148 return *this;
00149 }
00150
00151 template<class _U1, class _U2>
00152 pair&
00153 operator=(const pair<_U1, _U2>& __p)
00154 {
00155 first = __p.first;
00156 second = __p.second;
00157 return *this;
00158 }
00159
00160 template<class _U1, class _U2>
00161 pair&
00162 operator=(pair<_U1, _U2>&& __p)
00163 {
00164 first = std::move(__p.first);
00165 second = std::move(__p.second);
00166 return *this;
00167 }
00168
00169 void
00170 swap(pair& __p)
00171 {
00172 using std::swap;
00173 swap(first, __p.first);
00174 swap(second, __p.second);
00175 }
00176
00177 private:
00178 template<typename _Tp, typename... _Args>
00179 static _Tp
00180 __cons(tuple<_Args...>&&);
00181
00182 template<typename _Tp, typename... _Args, int... _Indexes>
00183 static _Tp
00184 __do_cons(tuple<_Args...>&&, const _Index_tuple<_Indexes...>&);
00185 #endif
00186 };
00187
00188
00189 template<class _T1, class _T2>
00190 inline bool
00191 operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00192 { return __x.first == __y.first && __x.second == __y.second; }
00193
00194
00195 template<class _T1, class _T2>
00196 inline bool
00197 operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00198 { return __x.first < __y.first
00199 || (!(__y.first < __x.first) && __x.second < __y.second); }
00200
00201
00202 template<class _T1, class _T2>
00203 inline bool
00204 operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00205 { return !(__x == __y); }
00206
00207
00208 template<class _T1, class _T2>
00209 inline bool
00210 operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00211 { return __y < __x; }
00212
00213
00214 template<class _T1, class _T2>
00215 inline bool
00216 operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00217 { return !(__y < __x); }
00218
00219
00220 template<class _T1, class _T2>
00221 inline bool
00222 operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
00223 { return !(__x < __y); }
00224
00225 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00226
00227
00228
00229 template<class _T1, class _T2>
00230 inline void
00231 swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
00232 { __x.swap(__y); }
00233 #endif
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 #ifndef __GXX_EXPERIMENTAL_CXX0X__
00248 template<class _T1, class _T2>
00249 inline pair<_T1, _T2>
00250 make_pair(_T1 __x, _T2 __y)
00251 { return pair<_T1, _T2>(__x, __y); }
00252 #else
00253
00254 template<class _T1, class _T2>
00255 inline pair<typename __decay_and_strip<_T1>::__type,
00256 typename __decay_and_strip<_T2>::__type>
00257 make_pair(_T1&& __x, _T2&& __y)
00258 {
00259 return pair<typename __decay_and_strip<_T1>::__type,
00260 typename __decay_and_strip<_T2>::__type>
00261 (std::forward<_T1>(__x), std::forward<_T2>(__y));
00262 }
00263 #endif
00264
00265 _GLIBCXX_END_NAMESPACE
00266
00267 #endif