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.

674 lines
18 KiB

  1. // functional standard header
  2. #pragma once
  3. #ifndef _FUNCTIONAL_
  4. #define _FUNCTIONAL_
  5. #include <xstddef>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. #pragma warning(disable: 4244)
  9. _STD_BEGIN
  10. // TEMPLATE STRUCT unary_function
  11. template<class _Arg,
  12. class _Result>
  13. struct unary_function
  14. { // base class for unary functions
  15. typedef _Arg argument_type;
  16. typedef _Result result_type;
  17. };
  18. // TEMPLATE STRUCT binary_function
  19. template<class _Arg1,
  20. class _Arg2,
  21. class _Result>
  22. struct binary_function
  23. { // base class for binary functions
  24. typedef _Arg1 first_argument_type;
  25. typedef _Arg2 second_argument_type;
  26. typedef _Result result_type;
  27. };
  28. // TEMPLATE STRUCT plus
  29. template<class _Ty>
  30. struct plus
  31. : public binary_function<_Ty, _Ty, _Ty>
  32. { // functor for operator+
  33. _Ty operator()(const _Ty& _Left, const _Ty& _Right) const
  34. { // apply operator+ to operands
  35. return (_Left + _Right);
  36. }
  37. };
  38. // TEMPLATE STRUCT minus
  39. template<class _Ty>
  40. struct minus
  41. : public binary_function<_Ty, _Ty, _Ty>
  42. { // functor for operator-
  43. _Ty operator()(const _Ty& _Left, const _Ty& _Right) const
  44. { // apply operator- to operands
  45. return (_Left - _Right);
  46. }
  47. };
  48. // TEMPLATE STRUCT multiplies
  49. template<class _Ty>
  50. struct multiplies
  51. : public binary_function<_Ty, _Ty, _Ty>
  52. { // functor for operator*
  53. _Ty operator()(const _Ty& _Left, const _Ty& _Right) const
  54. { // apply operator* to operands
  55. return (_Left * _Right);
  56. }
  57. };
  58. // TEMPLATE STRUCT divides
  59. template<class _Ty>
  60. struct divides
  61. : public binary_function<_Ty, _Ty, _Ty>
  62. { // functor for operator/
  63. _Ty operator()(const _Ty& _Left, const _Ty& _Right) const
  64. { // apply operator/ to operands
  65. return (_Left / _Right);
  66. }
  67. };
  68. // TEMPLATE STRUCT modulus
  69. template<class _Ty>
  70. struct modulus
  71. : public binary_function<_Ty, _Ty, _Ty>
  72. { // functor for operator%
  73. _Ty operator()(const _Ty& _Left, const _Ty& _Right) const
  74. { // apply operator% to operands
  75. return (_Left % _Right);
  76. }
  77. };
  78. // TEMPLATE STRUCT negate
  79. template<class _Ty>
  80. struct negate
  81. : public unary_function<_Ty, _Ty>
  82. { // functor for unary operator-
  83. _Ty operator()(const _Ty& _Left) const
  84. { // apply operator- to operand
  85. return (-_Left);
  86. }
  87. };
  88. // TEMPLATE STRUCT equal_to
  89. template<class _Ty>
  90. struct equal_to
  91. : public binary_function<_Ty, _Ty, bool>
  92. { // functor for operator==
  93. bool operator()(const _Ty& _Left, const _Ty& _Right) const
  94. { // apply operator== to operands
  95. return (_Left == _Right);
  96. }
  97. };
  98. // TEMPLATE STRUCT not_equal_to
  99. template<class _Ty>
  100. struct not_equal_to
  101. : public binary_function<_Ty, _Ty, bool>
  102. { // functor for operator!=
  103. bool operator()(const _Ty& _Left, const _Ty& _Right) const
  104. { // apply operator= to operands
  105. return (_Left != _Right);
  106. }
  107. };
  108. // TEMPLATE STRUCT greater
  109. template<class _Ty>
  110. struct greater
  111. : public binary_function<_Ty, _Ty, bool>
  112. { // functor for operator>
  113. bool operator()(const _Ty& _Left, const _Ty& _Right) const
  114. { // apply operator> to operands
  115. return (_Left > _Right);
  116. }
  117. };
  118. // TEMPLATE STRUCT less
  119. template<class _Ty>
  120. struct less
  121. : public binary_function<_Ty, _Ty, bool>
  122. { // functor for operator<
  123. bool operator()(const _Ty& _Left, const _Ty& _Right) const
  124. { // apply operator< to operands
  125. return (_Left < _Right);
  126. }
  127. };
  128. // TEMPLATE STRUCT greater_equal
  129. template<class _Ty>
  130. struct greater_equal
  131. : public binary_function<_Ty, _Ty, bool>
  132. { // functor for operator>=
  133. bool operator()(const _Ty& _Left, const _Ty& _Right) const
  134. { // apply operator>= to operands
  135. return (_Left >= _Right);
  136. }
  137. };
  138. // TEMPLATE STRUCT less_equal
  139. template<class _Ty>
  140. struct less_equal
  141. : public binary_function<_Ty, _Ty, bool>
  142. { // functor for operator<=
  143. bool operator()(const _Ty& _Left, const _Ty& _Right) const
  144. { // apply operator<= to operands
  145. return (_Left <= _Right);
  146. }
  147. };
  148. // TEMPLATE STRUCT logical_and
  149. template<class _Ty>
  150. struct logical_and
  151. : public binary_function<_Ty, _Ty, bool>
  152. { // functor for operator&&
  153. bool operator()(const _Ty& _Left, const _Ty& _Right) const
  154. { // apply operator&& to operands
  155. return (_Left && _Right);
  156. }
  157. };
  158. // TEMPLATE STRUCT logical_or
  159. template<class _Ty>
  160. struct logical_or
  161. : public binary_function<_Ty, _Ty, bool>
  162. { // functor for operator||
  163. bool operator()(const _Ty& _Left, const _Ty& _Right) const
  164. { // apply operator|| to operands
  165. return (_Left || _Right);
  166. }
  167. };
  168. // TEMPLATE STRUCT logical_not
  169. template<class _Ty>
  170. struct logical_not
  171. : public unary_function<_Ty, bool>
  172. { // functor for unary operator!
  173. bool operator()(const _Ty& _Left) const
  174. { // apply operator! to operand
  175. return (!_Left);
  176. }
  177. };
  178. // TEMPLATE CLASS unary_negate
  179. template<class _Fn1>
  180. class unary_negate
  181. : public unary_function<typename _Fn1::argument_type, bool>
  182. { // functor adapter !_Func(left)
  183. public:
  184. explicit unary_negate(const _Fn1& _Func)
  185. : _Functor(_Func)
  186. { // construct from functor
  187. }
  188. bool operator()(const typename _Fn1::argument_type& _Left) const
  189. { // apply functor to operand
  190. return (!_Functor(_Left));
  191. }
  192. protected:
  193. _Fn1 _Functor; // the functor to apply
  194. };
  195. // TEMPLATE FUNCTION not1
  196. template<class _Fn1> inline
  197. unary_negate<_Fn1> not1(const _Fn1& _Func)
  198. { // return a unary_negate functor adapter
  199. return (std::unary_negate<_Fn1>(_Func));
  200. }
  201. // TEMPLATE CLASS binary_negate
  202. template<class _Fn2>
  203. class binary_negate
  204. : public binary_function<typename _Fn2::first_argument_type,
  205. typename _Fn2::second_argument_type, bool>
  206. { // functor adapter !_Func(left, right)
  207. public:
  208. explicit binary_negate(const _Fn2& _Func)
  209. : _Functor(_Func)
  210. { // construct from functor
  211. }
  212. bool operator()(const typename _Fn2::first_argument_type& _Left,
  213. const typename _Fn2::second_argument_type& _Right) const
  214. { // apply functor to operands
  215. return (!_Functor(_Left, _Right));
  216. }
  217. protected:
  218. _Fn2 _Functor; // the functor to apply
  219. };
  220. // TEMPLATE FUNCTION not2
  221. template<class _Fn2> inline
  222. binary_negate<_Fn2> not2(const _Fn2& _Func)
  223. { // return a binary_negate functor adapter
  224. return (std::binary_negate<_Fn2>(_Func));
  225. }
  226. // TEMPLATE CLASS binder1st
  227. template<class _Fn2>
  228. class binder1st
  229. : public unary_function<typename _Fn2::second_argument_type,
  230. typename _Fn2::result_type>
  231. { // functor adapter _Func(stored, right)
  232. public:
  233. typedef unary_function<typename _Fn2::second_argument_type,
  234. typename _Fn2::result_type> _Base;
  235. typedef typename _Base::argument_type argument_type;
  236. typedef typename _Base::result_type result_type;
  237. binder1st(const _Fn2& _Func,
  238. const typename _Fn2::first_argument_type& _Left)
  239. : op(_Func), value(_Left)
  240. { // construct from functor and left operand
  241. }
  242. result_type operator()(const argument_type& _Right) const
  243. { // apply functor to operands
  244. return (op(value, _Right));
  245. }
  246. protected:
  247. _Fn2 op; // the functor to apply
  248. typename _Fn2::first_argument_type value; // the left operand
  249. };
  250. // TEMPLATE FUNCTION bind1st
  251. template<class _Fn2,
  252. class _Ty> inline
  253. binder1st<_Fn2> bind1st(const _Fn2& _Func, const _Ty& _Left)
  254. { // return a binder1st functor adapter
  255. typename _Fn2::first_argument_type _Val(_Left);
  256. return (std::binder1st<_Fn2>(_Func, _Val));
  257. }
  258. // TEMPLATE CLASS binder2nd
  259. template<class _Fn2>
  260. class binder2nd
  261. : public unary_function<typename _Fn2::first_argument_type,
  262. typename _Fn2::result_type>
  263. { // functor adapter _Func(left, stored)
  264. public:
  265. typedef unary_function<typename _Fn2::first_argument_type,
  266. typename _Fn2::result_type> _Base;
  267. typedef typename _Base::argument_type argument_type;
  268. typedef typename _Base::result_type result_type;
  269. binder2nd(const _Fn2& _Func,
  270. const typename _Fn2::second_argument_type& _Right)
  271. : op(_Func), value(_Right)
  272. { // construct from functor and right operand
  273. }
  274. result_type operator()(const argument_type& _Left) const
  275. { // apply functor to operands
  276. return (op(_Left, value));
  277. }
  278. protected:
  279. _Fn2 op; // the functor to apply
  280. typename _Fn2::second_argument_type value; // the right operand
  281. };
  282. // TEMPLATE FUNCTION bind2nd
  283. template<class _Fn2,
  284. class _Ty> inline
  285. binder2nd<_Fn2> bind2nd(const _Fn2& _Func, const _Ty& _Right)
  286. { // return a binder2nd functor adapter
  287. typename _Fn2::second_argument_type _Val(_Right);
  288. return (std::binder2nd<_Fn2>(_Func, _Val));
  289. }
  290. // TEMPLATE CLASS pointer_to_unary_function
  291. template<class _Arg,
  292. class _Result>
  293. class pointer_to_unary_function
  294. : public unary_function<_Arg, _Result>
  295. { // functor adapter (*pfunc)(left)
  296. public:
  297. explicit pointer_to_unary_function(_Result (__cdecl *_Left)(_Arg))
  298. : _Pfun(_Left)
  299. { // construct from pointer
  300. }
  301. _Result operator()(_Arg _Left) const
  302. { // call function with operand
  303. return (_Pfun(_Left));
  304. }
  305. protected:
  306. _Result (__cdecl *_Pfun)(_Arg); // the function pointer
  307. };
  308. // TEMPLATE CLASS pointer_to_binary_function
  309. template<class _Arg1,
  310. class _Arg2,
  311. class _Result>
  312. class pointer_to_binary_function
  313. : public binary_function<_Arg1, _Arg2, _Result>
  314. { // functor adapter (*pfunc)(left, right)
  315. public:
  316. explicit pointer_to_binary_function(
  317. _Result (__cdecl *_Left)(_Arg1, _Arg2))
  318. : _Pfun(_Left)
  319. { // construct from pointer
  320. }
  321. _Result operator()(_Arg1 _Left, _Arg2 _Right) const
  322. { // call function with operands
  323. return (_Pfun(_Left, _Right));
  324. }
  325. protected:
  326. _Result (__cdecl *_Pfun)(_Arg1, _Arg2); // the function pointer
  327. };
  328. // TEMPLATE FUNCTION ptr_fun
  329. template<class _Arg,
  330. class _Result> inline
  331. pointer_to_unary_function<_Arg, _Result>
  332. ptr_fun(_Result (__cdecl *_Left)(_Arg))
  333. { // return pointer_to_unary_function functor adapter
  334. return (std::pointer_to_unary_function<_Arg, _Result>(_Left));
  335. }
  336. template<class _Arg1,
  337. class _Arg2,
  338. class _Result> inline
  339. pointer_to_binary_function<_Arg1, _Arg2, _Result>
  340. ptr_fun(_Result (__cdecl *_Left)(_Arg1, _Arg2))
  341. { // return pointer_to_binary_function functor adapter
  342. return (std::pointer_to_binary_function<_Arg1, _Arg2, _Result>(_Left));
  343. }
  344. // TEMPLATE CLASS mem_fun_t
  345. template<class _Result,
  346. class _Ty>
  347. class mem_fun_t
  348. : public unary_function<_Ty *, _Result>
  349. { // functor adapter (*p->*pfunc)(), non-const *pfunc
  350. public:
  351. explicit mem_fun_t(_Result (_Ty::*_Pm)())
  352. : _Pmemfun(_Pm)
  353. { // construct from pointer
  354. }
  355. _Result operator()(_Ty *_Pleft) const
  356. { // call function
  357. return ((_Pleft->*_Pmemfun)());
  358. }
  359. private:
  360. _Result (_Ty::*_Pmemfun)(); // the member function pointer
  361. };
  362. // TEMPLATE CLASS mem_fun1_t
  363. template<class _Result,
  364. class _Ty,
  365. class _Arg>
  366. class mem_fun1_t
  367. : public binary_function<_Ty *, _Arg, _Result>
  368. { // functor adapter (*p->*pfunc)(val), non-const *pfunc
  369. public:
  370. explicit mem_fun1_t(_Result (_Ty::*_Pm)(_Arg))
  371. : _Pmemfun(_Pm)
  372. { // construct from pointer
  373. }
  374. _Result operator()(_Ty *_Pleft, _Arg _Right) const
  375. { // call function with operand
  376. return ((_Pleft->*_Pmemfun)(_Right));
  377. }
  378. private:
  379. _Result (_Ty::*_Pmemfun)(_Arg); // the member function pointer
  380. };
  381. // TEMPLATE CLASS const_mem_fun_t
  382. template<class _Result,
  383. class _Ty>
  384. class const_mem_fun_t
  385. : public unary_function<const _Ty *, _Result>
  386. { // functor adapter (*p->*pfunc)(), const *pfunc
  387. public:
  388. explicit const_mem_fun_t(_Result (_Ty::*_Pm)() const)
  389. : _Pmemfun(_Pm)
  390. { // construct from pointer
  391. }
  392. _Result operator()(const _Ty *_Pleft) const
  393. { // call function
  394. return ((_Pleft->*_Pmemfun)());
  395. }
  396. private:
  397. _Result (_Ty::*_Pmemfun)() const; // the member function pointer
  398. };
  399. // TEMPLATE CLASS const_mem_fun1_t
  400. template<class _Result,
  401. class _Ty,
  402. class _Arg>
  403. class const_mem_fun1_t
  404. : public binary_function<_Ty *, _Arg, _Result>
  405. { // functor adapter (*p->*pfunc)(val), const *pfunc
  406. public:
  407. explicit const_mem_fun1_t(_Result (_Ty::*_Pm)(_Arg) const)
  408. : _Pmemfun(_Pm)
  409. { // construct from pointer
  410. }
  411. _Result operator()(const _Ty *_Pleft, _Arg _Right) const
  412. { // call function with operand
  413. return ((_Pleft->*_Pmemfun)(_Right));
  414. }
  415. private:
  416. _Result (_Ty::*_Pmemfun)(_Arg) const; // the member function pointer
  417. };
  418. // TEMPLATE FUNCTION mem_fun
  419. template<class _Result,
  420. class _Ty> inline
  421. mem_fun_t<_Result, _Ty> mem_fun(_Result (_Ty::*_Pm)())
  422. { // return a mem_fun_t functor adapter
  423. return (std::mem_fun_t<_Result, _Ty>(_Pm));
  424. }
  425. template<class _Result,
  426. class _Ty,
  427. class _Arg> inline
  428. mem_fun1_t<_Result, _Ty, _Arg> mem_fun(_Result (_Ty::*_Pm)(_Arg))
  429. { // return a mem_fun1_t functor adapter
  430. return (std::mem_fun1_t<_Result, _Ty, _Arg>(_Pm));
  431. }
  432. template<class _Result,
  433. class _Ty> inline
  434. const_mem_fun_t<_Result, _Ty>
  435. mem_fun(_Result (_Ty::*_Pm)() const)
  436. { // return a const_mem_fun_t functor adapter
  437. return (std::const_mem_fun_t<_Result, _Ty>(_Pm));
  438. }
  439. template<class _Result,
  440. class _Ty,
  441. class _Arg> inline
  442. const_mem_fun1_t<_Result, _Ty, _Arg>
  443. mem_fun(_Result (_Ty::*_Pm)(_Arg) const)
  444. { // return a const_mem_fun1_t functor adapter
  445. return (std::const_mem_fun1_t<_Result, _Ty, _Arg>(_Pm));
  446. }
  447. // TEMPLATE FUNCTION mem_fun1 (retained)
  448. template<class _Result,
  449. class _Ty,
  450. class _Arg> inline
  451. mem_fun1_t<_Result, _Ty, _Arg> mem_fun1(_Result (_Ty::*_Pm)(_Arg))
  452. { // return a mem_fun1_t functor adapter
  453. return (std::mem_fun1_t<_Result, _Ty, _Arg>(_Pm));
  454. }
  455. // TEMPLATE CLASS mem_fun_ref_t
  456. template<class _Result,
  457. class _Ty>
  458. class mem_fun_ref_t
  459. : public unary_function<_Ty, _Result>
  460. { // functor adapter (*left.*pfunc)(), non-const *pfunc
  461. public:
  462. explicit mem_fun_ref_t(_Result (_Ty::*_Pm)())
  463. : _Pmemfun(_Pm)
  464. { // construct from pointer
  465. }
  466. _Result operator()(_Ty& _Left) const
  467. { // call function
  468. return ((_Left.*_Pmemfun)());
  469. }
  470. private:
  471. _Result (_Ty::*_Pmemfun)(); // the member function pointer
  472. };
  473. // TEMPLATE CLASS mem_fun1_ref_t
  474. template<class _Result,
  475. class _Ty,
  476. class _Arg>
  477. class mem_fun1_ref_t
  478. : public binary_function<_Ty, _Arg, _Result>
  479. { // functor adapter (*left.*pfunc)(val), non-const *pfunc
  480. public:
  481. explicit mem_fun1_ref_t(_Result (_Ty::*_Pm)(_Arg))
  482. : _Pmemfun(_Pm)
  483. { // construct from pointer
  484. }
  485. _Result operator()(_Ty& _Left, _Arg _Right) const
  486. { // call function with operand
  487. return ((_Left.*_Pmemfun)(_Right));
  488. }
  489. private:
  490. _Result (_Ty::*_Pmemfun)(_Arg); // the member function pointer
  491. };
  492. // TEMPLATE CLASS const_mem_fun_ref_t
  493. template<class _Result,
  494. class _Ty>
  495. class const_mem_fun_ref_t
  496. : public unary_function<_Ty, _Result>
  497. { // functor adapter (*left.*pfunc)(), const *pfunc
  498. public:
  499. explicit const_mem_fun_ref_t(_Result (_Ty::*_Pm)() const)
  500. : _Pmemfun(_Pm)
  501. { // construct from pointer
  502. }
  503. _Result operator()(const _Ty& _Left) const
  504. { // call function
  505. return ((_Left.*_Pmemfun)());
  506. }
  507. private:
  508. _Result (_Ty::*_Pmemfun)() const; // the member function pointer
  509. };
  510. // TEMPLATE CLASS const_mem_fun1_ref_t
  511. template<class _Result,
  512. class _Ty,
  513. class _Arg>
  514. class const_mem_fun1_ref_t
  515. : public binary_function<_Ty, _Arg, _Result>
  516. { // functor adapter (*left.*pfunc)(val), const *pfunc
  517. public:
  518. explicit const_mem_fun1_ref_t(_Result (_Ty::*_Pm)(_Arg) const)
  519. : _Pmemfun(_Pm)
  520. { // construct from pointer
  521. }
  522. _Result operator()(const _Ty& _Left, _Arg _Right) const
  523. { // call function with operand
  524. return ((_Left.*_Pmemfun)(_Right));
  525. }
  526. private:
  527. _Result (_Ty::*_Pmemfun)(_Arg) const; // the member function pointer
  528. };
  529. // TEMPLATE FUNCTION mem_fun_ref
  530. template<class _Result,
  531. class _Ty> inline
  532. mem_fun_ref_t<_Result, _Ty> mem_fun_ref(_Result (_Ty::*_Pm)())
  533. { // return a mem_fun_ref_t functor adapter
  534. return (std::mem_fun_ref_t<_Result, _Ty>(_Pm));
  535. }
  536. template<class _Result,
  537. class _Ty,
  538. class _Arg> inline
  539. mem_fun1_ref_t<_Result, _Ty, _Arg>
  540. mem_fun_ref(_Result (_Ty::*_Pm)(_Arg))
  541. { // return a mem_fun1_ref_t functor adapter
  542. return (std::mem_fun1_ref_t<_Result, _Ty, _Arg>(_Pm));
  543. }
  544. template<class _Result,
  545. class _Ty> inline
  546. const_mem_fun_ref_t<_Result, _Ty>
  547. mem_fun_ref(_Result (_Ty::*_Pm)() const)
  548. { // return a const_mem_fun_ref_t functor adapter
  549. return (std::const_mem_fun_ref_t<_Result, _Ty>(_Pm));
  550. }
  551. template<class _Result,
  552. class _Ty,
  553. class _Arg> inline
  554. const_mem_fun1_ref_t<_Result, _Ty, _Arg>
  555. mem_fun_ref(_Result (_Ty::*_Pm)(_Arg) const)
  556. { // return a const_mem_fun1_ref_t functor adapter
  557. return (std::const_mem_fun1_ref_t<_Result, _Ty, _Arg>(_Pm));
  558. }
  559. // TEMPLATE FUNCTION mem_fun1_ref (retained)
  560. template<class _Result,
  561. class _Ty,
  562. class _Arg> inline
  563. mem_fun1_ref_t<_Result, _Ty, _Arg> mem_fun1_ref(_Result (_Ty::*_Pm)(_Arg))
  564. { // return a mem_fun1_ref_t functor adapter
  565. return (std::mem_fun1_ref_t<_Result, _Ty, _Arg>(_Pm));
  566. }
  567. _STD_END
  568. #pragma warning(default: 4244)
  569. #pragma warning(pop)
  570. #pragma pack(pop)
  571. #endif /* _FUNCTIONAL_ */
  572. /*
  573. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  574. * Consult your license regarding permissions and restrictions.
  575. */
  576. /*
  577. * This file is derived from software bearing the following
  578. * restrictions:
  579. *
  580. * Copyright (c) 1994
  581. * Hewlett-Packard Company
  582. *
  583. * Permission to use, copy, modify, distribute and sell this
  584. * software and its documentation for any purpose is hereby
  585. * granted without fee, provided that the above copyright notice
  586. * appear in all copies and that both that copyright notice and
  587. * this permission notice appear in supporting documentation.
  588. * Hewlett-Packard Company makes no representations about the
  589. * suitability of this software for any purpose. It is provided
  590. * "as is" without express or implied warranty.
  591. V3.10:0009 */