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 _EXT_FUNCTIONAL
00058 #define _EXT_FUNCTIONAL 1
00059
00060 #pragma GCC system_header
00061
00062 #include <functional>
00063
00064 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
00065 {
00066 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00067
00068 using std::size_t;
00069 using std::unary_function;
00070 using std::binary_function;
00071 using std::mem_fun1_t;
00072 using std::const_mem_fun1_t;
00073 using std::mem_fun1_ref_t;
00074 using std::const_mem_fun1_ref_t;
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 template <class _Tp>
00087 inline _Tp
00088 identity_element(std::plus<_Tp>)
00089 { return _Tp(0); }
00090
00091
00092 template <class _Tp>
00093 inline _Tp
00094 identity_element(std::multiplies<_Tp>)
00095 { return _Tp(1); }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 template <class _Operation1, class _Operation2>
00126 class unary_compose
00127 : public unary_function<typename _Operation2::argument_type,
00128 typename _Operation1::result_type>
00129 {
00130 protected:
00131 _Operation1 _M_fn1;
00132 _Operation2 _M_fn2;
00133
00134 public:
00135 unary_compose(const _Operation1& __x, const _Operation2& __y)
00136 : _M_fn1(__x), _M_fn2(__y) {}
00137
00138 typename _Operation1::result_type
00139 operator()(const typename _Operation2::argument_type& __x) const
00140 { return _M_fn1(_M_fn2(__x)); }
00141 };
00142
00143
00144 template <class _Operation1, class _Operation2>
00145 inline unary_compose<_Operation1, _Operation2>
00146 compose1(const _Operation1& __fn1, const _Operation2& __fn2)
00147 { return unary_compose<_Operation1,_Operation2>(__fn1, __fn2); }
00148
00149
00150 template <class _Operation1, class _Operation2, class _Operation3>
00151 class binary_compose
00152 : public unary_function<typename _Operation2::argument_type,
00153 typename _Operation1::result_type>
00154 {
00155 protected:
00156 _Operation1 _M_fn1;
00157 _Operation2 _M_fn2;
00158 _Operation3 _M_fn3;
00159
00160 public:
00161 binary_compose(const _Operation1& __x, const _Operation2& __y,
00162 const _Operation3& __z)
00163 : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }
00164
00165 typename _Operation1::result_type
00166 operator()(const typename _Operation2::argument_type& __x) const
00167 { return _M_fn1(_M_fn2(__x), _M_fn3(__x)); }
00168 };
00169
00170
00171 template <class _Operation1, class _Operation2, class _Operation3>
00172 inline binary_compose<_Operation1, _Operation2, _Operation3>
00173 compose2(const _Operation1& __fn1, const _Operation2& __fn2,
00174 const _Operation3& __fn3)
00175 { return binary_compose<_Operation1, _Operation2, _Operation3>
00176 (__fn1, __fn2, __fn3); }
00177
00178
00179
00180
00181
00182
00183
00184
00185 template <class _Tp>
00186 struct identity : public std::_Identity<_Tp> {};
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 template <class _Pair>
00200 struct select1st : public std::_Select1st<_Pair> {};
00201
00202
00203 template <class _Pair>
00204 struct select2nd : public std::_Select2nd<_Pair> {};
00205
00206
00207
00208 template <class _Arg1, class _Arg2>
00209 struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1>
00210 {
00211 _Arg1
00212 operator()(const _Arg1& __x, const _Arg2&) const
00213 { return __x; }
00214 };
00215
00216 template <class _Arg1, class _Arg2>
00217 struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2>
00218 {
00219 _Arg2
00220 operator()(const _Arg1&, const _Arg2& __y) const
00221 { return __y; }
00222 };
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 template <class _Arg1, class _Arg2>
00234 struct project1st : public _Project1st<_Arg1, _Arg2> {};
00235
00236
00237 template <class _Arg1, class _Arg2>
00238 struct project2nd : public _Project2nd<_Arg1, _Arg2> {};
00239
00240
00241
00242 template <class _Result>
00243 struct _Constant_void_fun
00244 {
00245 typedef _Result result_type;
00246 result_type _M_val;
00247
00248 _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
00249
00250 const result_type&
00251 operator()() const
00252 { return _M_val; }
00253 };
00254
00255 template <class _Result, class _Argument>
00256 struct _Constant_unary_fun
00257 {
00258 typedef _Argument argument_type;
00259 typedef _Result result_type;
00260 result_type _M_val;
00261
00262 _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
00263
00264 const result_type&
00265 operator()(const _Argument&) const
00266 { return _M_val; }
00267 };
00268
00269 template <class _Result, class _Arg1, class _Arg2>
00270 struct _Constant_binary_fun
00271 {
00272 typedef _Arg1 first_argument_type;
00273 typedef _Arg2 second_argument_type;
00274 typedef _Result result_type;
00275 _Result _M_val;
00276
00277 _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
00278
00279 const result_type&
00280 operator()(const _Arg1&, const _Arg2&) const
00281 { return _M_val; }
00282 };
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 template <class _Result>
00300 struct constant_void_fun
00301 : public _Constant_void_fun<_Result>
00302 {
00303 constant_void_fun(const _Result& __v)
00304 : _Constant_void_fun<_Result>(__v) {}
00305 };
00306
00307
00308 template <class _Result, class _Argument = _Result>
00309 struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument>
00310 {
00311 constant_unary_fun(const _Result& __v)
00312 : _Constant_unary_fun<_Result, _Argument>(__v) {}
00313 };
00314
00315
00316 template <class _Result, class _Arg1 = _Result, class _Arg2 = _Arg1>
00317 struct constant_binary_fun
00318 : public _Constant_binary_fun<_Result, _Arg1, _Arg2>
00319 {
00320 constant_binary_fun(const _Result& __v)
00321 : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
00322 };
00323
00324
00325 template <class _Result>
00326 inline constant_void_fun<_Result>
00327 constant0(const _Result& __val)
00328 { return constant_void_fun<_Result>(__val); }
00329
00330
00331 template <class _Result>
00332 inline constant_unary_fun<_Result, _Result>
00333 constant1(const _Result& __val)
00334 { return constant_unary_fun<_Result, _Result>(__val); }
00335
00336
00337 template <class _Result>
00338 inline constant_binary_fun<_Result,_Result,_Result>
00339 constant2(const _Result& __val)
00340 { return constant_binary_fun<_Result, _Result, _Result>(__val); }
00341
00342
00343
00344
00345
00346
00347
00348
00349 class subtractive_rng
00350 : public unary_function<unsigned int, unsigned int>
00351 {
00352 private:
00353 unsigned int _M_table[55];
00354 size_t _M_index1;
00355 size_t _M_index2;
00356
00357 public:
00358
00359 unsigned int
00360 operator()(unsigned int __limit)
00361 {
00362 _M_index1 = (_M_index1 + 1) % 55;
00363 _M_index2 = (_M_index2 + 1) % 55;
00364 _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2];
00365 return _M_table[_M_index1] % __limit;
00366 }
00367
00368 void
00369 _M_initialize(unsigned int __seed)
00370 {
00371 unsigned int __k = 1;
00372 _M_table[54] = __seed;
00373 size_t __i;
00374 for (__i = 0; __i < 54; __i++)
00375 {
00376 size_t __ii = (21 * (__i + 1) % 55) - 1;
00377 _M_table[__ii] = __k;
00378 __k = __seed - __k;
00379 __seed = _M_table[__ii];
00380 }
00381 for (int __loop = 0; __loop < 4; __loop++)
00382 {
00383 for (__i = 0; __i < 55; __i++)
00384 _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];
00385 }
00386 _M_index1 = 0;
00387 _M_index2 = 31;
00388 }
00389
00390
00391 subtractive_rng(unsigned int __seed)
00392 { _M_initialize(__seed); }
00393
00394
00395 subtractive_rng()
00396 { _M_initialize(161803398u); }
00397 };
00398
00399
00400
00401
00402
00403 template <class _Ret, class _Tp, class _Arg>
00404 inline mem_fun1_t<_Ret, _Tp, _Arg>
00405 mem_fun1(_Ret (_Tp::*__f)(_Arg))
00406 { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
00407
00408 template <class _Ret, class _Tp, class _Arg>
00409 inline const_mem_fun1_t<_Ret, _Tp, _Arg>
00410 mem_fun1(_Ret (_Tp::*__f)(_Arg) const)
00411 { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
00412
00413 template <class _Ret, class _Tp, class _Arg>
00414 inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
00415 mem_fun1_ref(_Ret (_Tp::*__f)(_Arg))
00416 { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
00417
00418 template <class _Ret, class _Tp, class _Arg>
00419 inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
00420 mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const)
00421 { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
00422
00423 _GLIBCXX_END_NAMESPACE_VERSION
00424 }
00425
00426 #endif
00427