Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

308 lines
9.3 KiB

  1. // functional standard header
  2. #ifndef _FUNCTIONAL_
  3. #define _FUNCTIONAL_
  4. #include <xstddef>
  5. #ifdef _MSC_VER
  6. #pragma pack(push,8)
  7. #endif /* _MSC_VER */
  8. _STD_BEGIN
  9. // TEMPLATE STRUCT unary_function
  10. template<class _A, class _R>
  11. struct unary_function {
  12. typedef _A argument_type;
  13. typedef _R result_type;
  14. };
  15. // TEMPLATE STRUCT binary_function
  16. template<class _A1, class _A2, class _R>
  17. struct binary_function {
  18. typedef _A1 first_argument_type;
  19. typedef _A2 second_argument_type;
  20. typedef _R result_type;
  21. };
  22. // TEMPLATE STRUCT plus
  23. template<class _Ty>
  24. struct plus : binary_function<_Ty, _Ty, _Ty> {
  25. _Ty operator()(const _Ty& _X, const _Ty& _Y) const
  26. {return (_X + _Y); }
  27. };
  28. // TEMPLATE STRUCT minus
  29. template<class _Ty>
  30. struct minus : binary_function<_Ty, _Ty, _Ty> {
  31. _Ty operator()(const _Ty& _X, const _Ty& _Y) const
  32. {return (_X - _Y); }
  33. };
  34. // TEMPLATE STRUCT multiplies
  35. template<class _Ty>
  36. struct multiplies : binary_function<_Ty, _Ty, _Ty> {
  37. _Ty operator()(const _Ty& _X, const _Ty& _Y) const
  38. {return (_X * _Y); }
  39. };
  40. // TEMPLATE STRUCT divides
  41. template<class _Ty>
  42. struct divides : binary_function<_Ty, _Ty, _Ty> {
  43. _Ty operator()(const _Ty& _X, const _Ty& _Y) const
  44. {return (_X / _Y); }
  45. };
  46. // TEMPLATE STRUCT modulus
  47. template<class _Ty>
  48. struct modulus : binary_function<_Ty, _Ty, _Ty> {
  49. _Ty operator()(const _Ty& _X, const _Ty& _Y) const
  50. {return (_X % _Y); }
  51. };
  52. // TEMPLATE STRUCT negate
  53. template<class _Ty>
  54. struct negate : unary_function<_Ty, _Ty> {
  55. _Ty operator()(const _Ty& _X) const
  56. {return (-_X); }
  57. };
  58. // TEMPLATE STRUCT equal_to
  59. template<class _Ty>
  60. struct equal_to : binary_function<_Ty, _Ty, bool> {
  61. bool operator()(const _Ty& _X, const _Ty& _Y) const
  62. {return (_X == _Y); }
  63. };
  64. // TEMPLATE STRUCT not_equal_to
  65. template<class _Ty>
  66. struct not_equal_to : binary_function<_Ty, _Ty, bool> {
  67. bool operator()(const _Ty& _X, const _Ty& _Y) const
  68. {return (_X != _Y); }
  69. };
  70. // TEMPLATE STRUCT greater
  71. template<class _Ty>
  72. struct greater : binary_function<_Ty, _Ty, bool> {
  73. bool operator()(const _Ty& _X, const _Ty& _Y) const
  74. {return (_X > _Y); }
  75. };
  76. // TEMPLATE STRUCT less
  77. template<class _Ty>
  78. struct less : binary_function<_Ty, _Ty, bool> {
  79. bool operator()(const _Ty& _X, const _Ty& _Y) const
  80. {return (_X < _Y); }
  81. };
  82. // TEMPLATE STRUCT greater_equal
  83. template<class _Ty>
  84. struct greater_equal : binary_function<_Ty, _Ty, bool> {
  85. bool operator()(const _Ty& _X, const _Ty& _Y) const
  86. {return (_X >= _Y); }
  87. };
  88. // TEMPLATE STRUCT less_equal
  89. template<class _Ty>
  90. struct less_equal : binary_function<_Ty, _Ty, bool> {
  91. bool operator()(const _Ty& _X, const _Ty& _Y) const
  92. {return (_X <= _Y); }
  93. };
  94. // TEMPLATE STRUCT logical_and
  95. template<class _Ty>
  96. struct logical_and : binary_function<_Ty, _Ty, bool> {
  97. bool operator()(const _Ty& _X, const _Ty& _Y) const
  98. {return (_X && _Y); }
  99. };
  100. // TEMPLATE STRUCT logical_or
  101. template<class _Ty>
  102. struct logical_or : binary_function<_Ty, _Ty, bool> {
  103. bool operator()(const _Ty& _X, const _Ty& _Y) const
  104. {return (_X || _Y); }
  105. };
  106. // TEMPLATE STRUCT logical_not
  107. template<class _Ty>
  108. struct logical_not : unary_function<_Ty, bool> {
  109. bool operator()(const _Ty& _X) const
  110. {return (!_X); }
  111. };
  112. // TEMPLATE CLASS unary_negate
  113. template<class _Ufn>
  114. class unary_negate
  115. : public unary_function<typename _Ufn::argument_type, bool> {
  116. public:
  117. explicit unary_negate(const _Ufn& _X)
  118. : _Fn(_X) {}
  119. bool operator()(const typename _Ufn::argument_type& _X) const
  120. {return (!_Fn(_X)); }
  121. protected:
  122. _Ufn _Fn;
  123. };
  124. // TEMPLATE FUNCTION not1
  125. template<class _Ufn> inline
  126. unary_negate<_Ufn> not1(const _Ufn& _X)
  127. {return (unary_negate<_Ufn>(_X)); }
  128. // TEMPLATE CLASS binary_negate
  129. template<class _Bfn>
  130. class binary_negate
  131. : public binary_function<typename _Bfn::first_argument_type,
  132. typename _Bfn::second_argument_type, bool> {
  133. public:
  134. explicit binary_negate(const _Bfn& _X)
  135. : _Fn(_X) {}
  136. bool operator()(const typename _Bfn::first_argument_type& _X,
  137. const typename _Bfn::second_argument_type& _Y) const
  138. {return (!_Fn(_X, _Y)); }
  139. protected:
  140. _Bfn _Fn;
  141. };
  142. // TEMPLATE FUNCTION not2
  143. template<class _Bfn> inline
  144. binary_negate<_Bfn> not2(const _Bfn& _X)
  145. {return (binary_negate<_Bfn>(_X)); }
  146. // TEMPLATE CLASS binder1st
  147. template<class _Bfn>
  148. class binder1st
  149. : public unary_function<typename _Bfn::second_argument_type,
  150. typename _Bfn::result_type> {
  151. public:
  152. binder1st(const _Bfn& _X,
  153. typename const _Bfn::first_argument_type& _Y)
  154. : op(_X), value(_Y) {}
  155. result_type operator()(const argument_type& _X) const
  156. {return (op(value, _X)); }
  157. protected:
  158. _Bfn op;
  159. typename _Bfn::first_argument_type value;
  160. };
  161. // TEMPLATE FUNCTION bind1st
  162. template<class _Bfn, class _Ty> inline
  163. binder1st<_Bfn> bind1st(const _Bfn& _X, const _Ty& _Y)
  164. {return (binder1st<_Bfn>(_X,
  165. _Bfn::first_argument_type(_Y))); }
  166. // TEMPLATE CLASS binder2nd
  167. template<class _Bfn>
  168. class binder2nd
  169. : public unary_function<typename _Bfn::first_argument_type,
  170. typename _Bfn::result_type> {
  171. public:
  172. binder2nd(const _Bfn& _X,
  173. const typename _Bfn::second_argument_type& _Y)
  174. : op(_X), value(_Y) {}
  175. result_type operator()(const argument_type& _X) const
  176. {return (op(_X, value)); }
  177. protected:
  178. _Bfn op;
  179. typename _Bfn::second_argument_type value;
  180. };
  181. // TEMPLATE FUNCTION bind2nd
  182. template<class _Bfn, class _Ty> inline
  183. binder2nd<_Bfn> bind2nd(const _Bfn& _X, const _Ty& _Y)
  184. {return (binder2nd<_Bfn>(_X,
  185. _Bfn::second_argument_type(_Y))); }
  186. // TEMPLATE CLASS pointer_to_unary_function
  187. template<class _A, class _R>
  188. class pointer_to_unary_function
  189. : public unary_function<_A, _R> {
  190. public:
  191. explicit pointer_to_unary_function(_R (__cdecl *_X)(_A))
  192. : _Fn(_X) {}
  193. _R operator()(_A _X) const
  194. {return (_Fn(_X)); }
  195. protected:
  196. _R (__cdecl *_Fn)(_A);
  197. };
  198. // TEMPLATE CLASS pointer_to_binary_function
  199. template<class _A1, class _A2, class _R>
  200. class pointer_to_binary_function
  201. : public binary_function<_A1, _A2, _R> {
  202. public:
  203. explicit pointer_to_binary_function(
  204. _R (__cdecl *_X)(_A1, _A2))
  205. : _Fn(_X) {}
  206. _R operator()(_A1 _X, _A2 _Y) const
  207. {return (_Fn(_X, _Y)); }
  208. protected:
  209. _R (__cdecl *_Fn)(_A1, _A2);
  210. };
  211. // TEMPLATE FUNCTION ptr_fun
  212. template<class _A, class _R> inline
  213. pointer_to_unary_function<_A, _R>
  214. ptr_fun(_R (__cdecl *_X)(_A))
  215. {return (pointer_to_unary_function<_A, _R>(_X)); }
  216. template<class _A1, class _A2, class _R> inline
  217. pointer_to_binary_function<_A1, _A2, _R>
  218. ptr_fun(_R (__cdecl *_X)(_A1, _A2))
  219. {return (pointer_to_binary_function<_A1, _A2, _R>(_X)); }
  220. // TEMPLATE CLASS mem_fun_t
  221. template<class _R, class _Ty>
  222. class mem_fun_t : public unary_function<_Ty *, _R> {
  223. public:
  224. explicit mem_fun_t(_R (_Ty::*_Pm)())
  225. : _Ptr(_Pm) {}
  226. _R operator()(_Ty *_P) const
  227. {return ((_P->*_Ptr)()); }
  228. private:
  229. _R (_Ty::*_Ptr)();
  230. };
  231. // TEMPLATE FUNCTION mem_fun
  232. template<class _R, class _Ty> inline
  233. mem_fun_t<_R, _Ty> mem_fun(_R (_Ty::*_Pm)())
  234. {return (mem_fun_t<_R, _Ty>(_Pm)); }
  235. // TEMPLATE CLASS mem_fun1_t
  236. template<class _R, class _Ty, class _A>
  237. class mem_fun1_t : public binary_function<_Ty *, _A, _R> {
  238. public:
  239. explicit mem_fun1_t(_R (_Ty::*_Pm)(_A))
  240. : _Ptr(_Pm) {}
  241. _R operator()(_Ty *_P, _A _Arg) const
  242. {return ((_P->*_Ptr)(_Arg)); }
  243. private:
  244. _R (_Ty::*_Ptr)(_A);
  245. };
  246. // TEMPLATE FUNCTION mem_fun1
  247. template<class _R, class _Ty, class _A> inline
  248. mem_fun1_t<_R, _Ty, _A> mem_fun1(_R (_Ty::*_Pm)(_A))
  249. {return (mem_fun1_t<_R, _Ty, _A>(_Pm)); }
  250. // TEMPLATE CLASS mem_fun_ref_t
  251. template<class _R, class _Ty>
  252. class mem_fun_ref_t : public unary_function<_Ty, _R> {
  253. public:
  254. explicit mem_fun_ref_t(_R (_Ty::*_Pm)())
  255. : _Ptr(_Pm) {}
  256. _R operator()(_Ty& _X) const
  257. {return ((_X.*_Ptr)()); }
  258. private:
  259. _R (_Ty::*_Ptr)();
  260. };
  261. // TEMPLATE FUNCTION mem_fun_ref
  262. template<class _R, class _Ty> inline
  263. mem_fun_ref_t<_R, _Ty> mem_fun_ref(_R (_Ty::*_Pm)())
  264. {return (mem_fun_ref_t<_R, _Ty>(_Pm)); }
  265. // TEMPLATE CLASS mem_fun1_ref_t
  266. template<class _R, class _Ty, class _A>
  267. class mem_fun1_ref_t : public binary_function<_Ty *, _A, _R> {
  268. public:
  269. explicit mem_fun1_ref_t(_R (_Ty::*_Pm)(_A))
  270. : _Ptr(_Pm) {}
  271. _R operator()(_Ty& _X, _A _Arg) const
  272. {return ((_X.*_Ptr)(_Arg)); }
  273. private:
  274. _R (_Ty::*_Ptr)(_A);
  275. };
  276. // TEMPLATE FUNCTION mem_fun1_ref
  277. template<class _R, class _Ty, class _A> inline
  278. mem_fun1_ref_t<_R, _Ty, _A> mem_fun1_ref(_R (_Ty::*_Pm)(_A))
  279. {return (mem_fun1_ref_t<_R, _Ty, _A>(_Pm)); }
  280. _STD_END
  281. #ifdef _MSC_VER
  282. #pragma pack(pop)
  283. #endif /* _MSC_VER */
  284. #endif /* _FUNCTIONAL_ */
  285. /*
  286. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  287. * Consult your license regarding permissions and restrictions.
  288. */
  289. /*
  290. * This file is derived from software bearing the following
  291. * restrictions:
  292. *
  293. * Copyright (c) 1994
  294. * Hewlett-Packard Company
  295. *
  296. * Permission to use, copy, modify, distribute and sell this
  297. * software and its documentation for any purpose is hereby
  298. * granted without fee, provided that the above copyright notice
  299. * appear in all copies and that both that copyright notice and
  300. * this permission notice appear in supporting documentation.
  301. * Hewlett-Packard Company makes no representations about the
  302. * suitability of this software for any purpose. It is provided
  303. * "as is" without express or implied warranty.
  304. */