_function_adaptors.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Copyright (c) 1996-1998
  7. * Silicon Graphics Computer Systems, Inc.
  8. *
  9. * Copyright (c) 1997
  10. * Moscow Center for SPARC Technology
  11. *
  12. * Copyright (c) 1999
  13. * Boris Fomitchev
  14. *
  15. * Copyright (c) 2000
  16. * Pavel Kuznetsov
  17. *
  18. * Copyright (c) 2001
  19. * Meridian'93
  20. *
  21. * This material is provided "as is", with absolutely no warranty expressed
  22. * or implied. Any use is at your own risk.
  23. *
  24. * Permission to use or copy this software for any purpose is hereby granted
  25. * without fee, provided the above notices are retained on all copies.
  26. * Permission to modify the code and to distribute modified code is granted,
  27. * provided the above notices are retained, and a notice that the code was
  28. * modified is included with the above copyright notice.
  29. *
  30. */
  31. /* NOTE: This is an internal header file, included by other STL headers.
  32. * You should not attempt to use it directly.
  33. */
  34. // This file has noo macro protection as it is meant to be included several times
  35. // from other header.
  36. // Adaptor function objects: pointers to member functions.
  37. // There are a total of 16 = 2^4 function objects in this family.
  38. // (1) Member functions taking no arguments vs member functions taking
  39. // one argument.
  40. // (2) Call through pointer vs call through reference.
  41. // (3) Member function with void return type vs member function with
  42. // non-void return type.
  43. // (4) Const vs non-const member function.
  44. // Note that choice (3) is nothing more than a workaround: according
  45. // to the draft, compilers should handle void and non-void the same way.
  46. // This feature is not yet widely implemented, though. You can only use
  47. // member functions returning void if your compiler supports partial
  48. // specialization.
  49. // All of this complexity is in the function objects themselves. You can
  50. // ignore it by using the helper function mem_fun and mem_fun_ref,
  51. // which create whichever type of adaptor is appropriate.
  52. _STLP_BEGIN_NAMESPACE
  53. //This implementation will only be used if needed, that is to say when there is the return void bug
  54. //and when there is no partial template specialization
  55. #if defined (_STLP_DONT_RETURN_VOID) && defined (_STLP_NO_CLASS_PARTIAL_SPECIALIZATION) && defined (_STLP_MEMBER_TEMPLATE_CLASSES)
  56. template<class _Result, class _Tp>
  57. class _Mem_fun0_ptr : public unary_function<_Tp*, _Result> {
  58. protected:
  59. typedef _Result (_Tp::*__fun_type) ();
  60. explicit _Mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}
  61. public:
  62. _Result operator ()(_Tp* __p) const { return (__p->*_M_f)(); }
  63. private:
  64. __fun_type _M_f;
  65. };
  66. template<class _Result, class _Tp, class _Arg>
  67. class _Mem_fun1_ptr : public binary_function<_Tp*,_Arg,_Result> {
  68. protected:
  69. typedef _Result (_Tp::*__fun_type) (_Arg);
  70. explicit _Mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}
  71. public:
  72. _Result operator ()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
  73. private:
  74. __fun_type _M_f;
  75. };
  76. template<class _Result, class _Tp>
  77. class _Const_mem_fun0_ptr : public unary_function<const _Tp*,_Result> {
  78. protected:
  79. typedef _Result (_Tp::*__fun_type) () const;
  80. explicit _Const_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}
  81. public:
  82. _Result operator ()(const _Tp* __p) const { return (__p->*_M_f)(); }
  83. private:
  84. __fun_type _M_f;
  85. };
  86. template<class _Result, class _Tp, class _Arg>
  87. class _Const_mem_fun1_ptr : public binary_function<const _Tp*,_Arg,_Result> {
  88. protected:
  89. typedef _Result (_Tp::*__fun_type) (_Arg) const;
  90. explicit _Const_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}
  91. public:
  92. _Result operator ()(const _Tp* __p, _Arg __x) const {
  93. return (__p->*_M_f)(__x); }
  94. private:
  95. __fun_type _M_f;
  96. };
  97. template<class _Result, class _Tp>
  98. class _Mem_fun0_ref : public unary_function<_Tp,_Result> {
  99. protected:
  100. typedef _Result (_Tp::*__fun_type) ();
  101. explicit _Mem_fun0_ref(__fun_type __f) : _M_f(__f) {}
  102. public:
  103. _Result operator ()(_Tp& __p) const { return (__p.*_M_f)(); }
  104. private:
  105. __fun_type _M_f;
  106. };
  107. template<class _Result, class _Tp, class _Arg>
  108. class _Mem_fun1_ref : public binary_function<_Tp,_Arg,_Result> {
  109. protected:
  110. typedef _Result (_Tp::*__fun_type) (_Arg);
  111. explicit _Mem_fun1_ref(__fun_type __f) : _M_f(__f) {}
  112. public:
  113. _Result operator ()(_Tp& __p, _Arg __x) const { return (__p.*_M_f)(__x); }
  114. private:
  115. __fun_type _M_f;
  116. };
  117. template<class _Result, class _Tp>
  118. class _Const_mem_fun0_ref : public unary_function<_Tp,_Result> {
  119. protected:
  120. typedef _Result (_Tp::*__fun_type) () const;
  121. explicit _Const_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}
  122. public:
  123. _Result operator ()(const _Tp& __p) const { return (__p.*_M_f)(); }
  124. private:
  125. __fun_type _M_f;
  126. };
  127. template<class _Result, class _Tp, class _Arg>
  128. class _Const_mem_fun1_ref : public binary_function<_Tp,_Arg,_Result> {
  129. protected:
  130. typedef _Result (_Tp::*__fun_type) (_Arg) const;
  131. explicit _Const_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}
  132. public:
  133. _Result operator ()(const _Tp& __p, _Arg __x) const { return (__p.*_M_f)(__x); }
  134. private:
  135. __fun_type _M_f;
  136. };
  137. template<class _Result>
  138. struct _Mem_fun_traits {
  139. template<class _Tp>
  140. struct _Args0 {
  141. typedef _Mem_fun0_ptr<_Result,_Tp> _Ptr;
  142. typedef _Const_mem_fun0_ptr<_Result,_Tp> _Ptr_const;
  143. typedef _Mem_fun0_ref<_Result,_Tp> _Ref;
  144. typedef _Const_mem_fun0_ref<_Result,_Tp> _Ref_const;
  145. };
  146. template<class _Tp, class _Arg>
  147. struct _Args1 {
  148. typedef _Mem_fun1_ptr<_Result,_Tp,_Arg> _Ptr;
  149. typedef _Const_mem_fun1_ptr<_Result,_Tp,_Arg> _Ptr_const;
  150. typedef _Mem_fun1_ref<_Result,_Tp,_Arg> _Ref;
  151. typedef _Const_mem_fun1_ref<_Result,_Tp,_Arg> _Ref_const;
  152. };
  153. };
  154. template<class _Arg, class _Result>
  155. class _Ptr_fun1_base : public unary_function<_Arg, _Result> {
  156. protected:
  157. typedef _Result (*__fun_type) (_Arg);
  158. explicit _Ptr_fun1_base(__fun_type __f) : _M_f(__f) {}
  159. public:
  160. _Result operator()(_Arg __x) const { return _M_f(__x); }
  161. private:
  162. __fun_type _M_f;
  163. };
  164. template <class _Arg1, class _Arg2, class _Result>
  165. class _Ptr_fun2_base : public binary_function<_Arg1,_Arg2,_Result> {
  166. protected:
  167. typedef _Result (*__fun_type) (_Arg1, _Arg2);
  168. explicit _Ptr_fun2_base(__fun_type __f) : _M_f(__f) {}
  169. public:
  170. _Result operator()(_Arg1 __x, _Arg2 __y) const { return _M_f(__x, __y); }
  171. private:
  172. __fun_type _M_f;
  173. };
  174. template<class _Result>
  175. struct _Ptr_fun_traits {
  176. template<class _Arg> struct _Args1 {
  177. typedef _Ptr_fun1_base<_Arg,_Result> _Fun;
  178. };
  179. template<class _Arg1, class _Arg2> struct _Args2 {
  180. typedef _Ptr_fun2_base<_Arg1,_Arg2,_Result> _Fun;
  181. };
  182. };
  183. /* Specializations for void return type */
  184. template<class _Tp>
  185. class _Void_mem_fun0_ptr : public unary_function<_Tp*,void> {
  186. protected:
  187. typedef void (_Tp::*__fun_type) ();
  188. explicit _Void_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}
  189. public:
  190. void operator ()(_Tp* __p) const { (__p->*_M_f)(); }
  191. private:
  192. __fun_type _M_f;
  193. };
  194. template<class _Tp, class _Arg>
  195. class _Void_mem_fun1_ptr : public binary_function<_Tp*,_Arg,void> {
  196. protected:
  197. typedef void (_Tp::*__fun_type) (_Arg);
  198. explicit _Void_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}
  199. public:
  200. void operator ()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
  201. private:
  202. __fun_type _M_f;
  203. };
  204. template<class _Tp>
  205. class _Void_const_mem_fun0_ptr : public unary_function<const _Tp*,void> {
  206. protected:
  207. typedef void (_Tp::*__fun_type) () const;
  208. explicit _Void_const_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}
  209. public:
  210. void operator ()(const _Tp* __p) const { (__p->*_M_f)(); }
  211. private:
  212. __fun_type _M_f;
  213. };
  214. template<class _Tp, class _Arg>
  215. class _Void_const_mem_fun1_ptr : public binary_function<const _Tp*,_Arg,void> {
  216. protected:
  217. typedef void (_Tp::*__fun_type) (_Arg) const;
  218. explicit _Void_const_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}
  219. public:
  220. void operator ()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
  221. private:
  222. __fun_type _M_f;
  223. };
  224. template<class _Tp>
  225. class _Void_mem_fun0_ref : public unary_function<_Tp,void> {
  226. protected:
  227. typedef void (_Tp::*__fun_type) ();
  228. explicit _Void_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}
  229. public:
  230. void operator ()(_Tp& __p) const { (__p.*_M_f)(); }
  231. private:
  232. __fun_type _M_f;
  233. };
  234. template<class _Tp, class _Arg>
  235. class _Void_mem_fun1_ref : public binary_function<_Tp,_Arg,void> {
  236. protected:
  237. typedef void (_Tp::*__fun_type) (_Arg);
  238. explicit _Void_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}
  239. public:
  240. void operator ()(_Tp& __p, _Arg __x) const { (__p.*_M_f)(__x); }
  241. private:
  242. __fun_type _M_f;
  243. };
  244. template<class _Tp>
  245. class _Void_const_mem_fun0_ref : public unary_function<_Tp,void> {
  246. protected:
  247. typedef void (_Tp::*__fun_type) () const;
  248. explicit _Void_const_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}
  249. public:
  250. void operator ()(const _Tp& __p) const { (__p.*_M_f)(); }
  251. private:
  252. __fun_type _M_f;
  253. };
  254. template<class _Tp, class _Arg>
  255. class _Void_const_mem_fun1_ref : public binary_function<_Tp,_Arg,void> {
  256. protected:
  257. typedef void (_Tp::*__fun_type) (_Arg) const;
  258. explicit _Void_const_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}
  259. public:
  260. void operator ()(const _Tp& __p, _Arg __x) const { (__p.*_M_f)(__x); }
  261. private:
  262. __fun_type _M_f;
  263. };
  264. _STLP_TEMPLATE_NULL
  265. struct _Mem_fun_traits<void> {
  266. template<class _Tp> struct _Args0 {
  267. typedef _Void_mem_fun0_ptr<_Tp> _Ptr;
  268. typedef _Void_const_mem_fun0_ptr<_Tp> _Ptr_const;
  269. typedef _Void_mem_fun0_ref<_Tp> _Ref;
  270. typedef _Void_const_mem_fun0_ref<_Tp> _Ref_const;
  271. };
  272. template<class _Tp, class _Arg> struct _Args1 {
  273. typedef _Void_mem_fun1_ptr<_Tp,_Arg> _Ptr;
  274. typedef _Void_const_mem_fun1_ptr<_Tp,_Arg> _Ptr_const;
  275. typedef _Void_mem_fun1_ref<_Tp,_Arg> _Ref;
  276. typedef _Void_const_mem_fun1_ref<_Tp,_Arg> _Ref_const;
  277. };
  278. };
  279. template<class _Arg>
  280. class _Ptr_void_fun1_base : public unary_function<_Arg, void> {
  281. protected:
  282. typedef void (*__fun_type) (_Arg);
  283. explicit _Ptr_void_fun1_base(__fun_type __f) : _M_f(__f) {}
  284. public:
  285. void operator()(_Arg __x) const { _M_f(__x); }
  286. private:
  287. __fun_type _M_f;
  288. };
  289. template <class _Arg1, class _Arg2>
  290. class _Ptr_void_fun2_base : public binary_function<_Arg1,_Arg2,void> {
  291. protected:
  292. typedef void (*__fun_type) (_Arg1, _Arg2);
  293. explicit _Ptr_void_fun2_base(__fun_type __f) : _M_f(__f) {}
  294. public:
  295. void operator()(_Arg1 __x, _Arg2 __y) const { _M_f(__x, __y); }
  296. private:
  297. __fun_type _M_f;
  298. };
  299. _STLP_TEMPLATE_NULL
  300. struct _Ptr_fun_traits<void> {
  301. template<class _Arg> struct _Args1 {
  302. typedef _Ptr_void_fun1_base<_Arg> _Fun;
  303. };
  304. template<class _Arg1, class _Arg2> struct _Args2 {
  305. typedef _Ptr_void_fun2_base<_Arg1,_Arg2> _Fun;
  306. };
  307. };
  308. // pavel: need extra level of inheritance here since MSVC++ does not
  309. // accept traits-based fake partial specialization for template
  310. // arguments other than first
  311. template<class _Result, class _Arg>
  312. class _Ptr_fun1 :
  313. public _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Arg>::_Fun {
  314. protected:
  315. typedef typename _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Arg>::_Fun _Base;
  316. explicit _Ptr_fun1(typename _Base::__fun_type __f) : _Base(__f) {}
  317. };
  318. template<class _Result, class _Arg1, class _Arg2>
  319. class _Ptr_fun2 :
  320. public _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args2<_Arg1,_Arg2>::_Fun {
  321. protected:
  322. typedef typename _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args2<_Arg1,_Arg2>::_Fun _Base;
  323. explicit _Ptr_fun2(typename _Base::__fun_type __f) : _Base(__f) {}
  324. };
  325. template <class _Result, class _Tp>
  326. class mem_fun_t :
  327. public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr {
  328. typedef typename
  329. _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr _Base;
  330. public:
  331. explicit mem_fun_t(typename _Base::__fun_type __f) : _Base(__f) {}
  332. };
  333. template <class _Result, class _Tp>
  334. class const_mem_fun_t :
  335. public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr_const {
  336. typedef typename
  337. _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr_const _Base;
  338. public:
  339. explicit const_mem_fun_t(typename _Base::__fun_type __f) : _Base(__f) {}
  340. };
  341. template <class _Result, class _Tp>
  342. class mem_fun_ref_t :
  343. public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref {
  344. typedef typename
  345. _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref _Base;
  346. public:
  347. explicit mem_fun_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
  348. };
  349. template <class _Result, class _Tp>
  350. class const_mem_fun_ref_t :
  351. public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref_const {
  352. typedef typename
  353. _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref_const _Base;
  354. public:
  355. explicit const_mem_fun_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
  356. };
  357. template <class _Result, class _Tp, class _Arg>
  358. class mem_fun1_t :
  359. public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr {
  360. typedef typename
  361. _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr _Base;
  362. public:
  363. explicit mem_fun1_t(typename _Base::__fun_type __f) : _Base(__f) {}
  364. };
  365. template <class _Result, class _Tp, class _Arg>
  366. class const_mem_fun1_t :
  367. public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr_const {
  368. typedef typename
  369. _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr_const _Base;
  370. public:
  371. explicit const_mem_fun1_t(typename _Base::__fun_type __f) : _Base(__f) {}
  372. };
  373. template <class _Result, class _Tp, class _Arg>
  374. class mem_fun1_ref_t :
  375. public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref {
  376. typedef typename
  377. _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref _Base;
  378. public:
  379. explicit mem_fun1_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
  380. };
  381. template <class _Result, class _Tp, class _Arg>
  382. class const_mem_fun1_ref_t :
  383. public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref_const {
  384. typedef typename
  385. _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref_const _Base;
  386. public:
  387. explicit const_mem_fun1_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
  388. };
  389. template <class _Arg, class _Result>
  390. class pointer_to_unary_function :
  391. public _Ptr_fun1<_Result,_Arg> {
  392. typedef typename
  393. _Ptr_fun1<_Result,_Arg>::__fun_type __fun_type;
  394. public:
  395. explicit pointer_to_unary_function(__fun_type __f)
  396. : _Ptr_fun1<_Result,_Arg>(__f) {}
  397. };
  398. template <class _Arg1, class _Arg2, class _Result>
  399. class pointer_to_binary_function :
  400. public _Ptr_fun2<_Result,_Arg1,_Arg2> {
  401. typedef typename
  402. _Ptr_fun2<_Result,_Arg1,_Arg2>::__fun_type __fun_type;
  403. public:
  404. explicit pointer_to_binary_function(__fun_type __f)
  405. : _Ptr_fun2<_Result,_Arg1,_Arg2>(__f) {}
  406. };
  407. #else
  408. template <class _Ret, class _Tp>
  409. class mem_fun_t : public unary_function<_Tp*,_Ret> {
  410. typedef _Ret (_Tp::*__fun_type)(void);
  411. public:
  412. explicit mem_fun_t(__fun_type __pf) : _M_f(__pf) {}
  413. _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
  414. private:
  415. __fun_type _M_f;
  416. };
  417. template <class _Ret, class _Tp>
  418. class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
  419. typedef _Ret (_Tp::*__fun_type)(void) const;
  420. public:
  421. explicit const_mem_fun_t(__fun_type __pf) : _M_f(__pf) {}
  422. _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
  423. private:
  424. __fun_type _M_f;
  425. };
  426. template <class _Ret, class _Tp>
  427. class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
  428. typedef _Ret (_Tp::*__fun_type)(void);
  429. public:
  430. explicit mem_fun_ref_t(__fun_type __pf) : _M_f(__pf) {}
  431. _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
  432. private:
  433. __fun_type _M_f;
  434. };
  435. template <class _Ret, class _Tp>
  436. class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
  437. typedef _Ret (_Tp::*__fun_type)(void) const;
  438. public:
  439. explicit const_mem_fun_ref_t(__fun_type __pf) : _M_f(__pf) {}
  440. _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
  441. private:
  442. __fun_type _M_f;
  443. };
  444. template <class _Ret, class _Tp, class _Arg>
  445. class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
  446. typedef _Ret (_Tp::*__fun_type)(_Arg);
  447. public:
  448. explicit mem_fun1_t(__fun_type __pf) : _M_f(__pf) {}
  449. _Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
  450. private:
  451. __fun_type _M_f;
  452. };
  453. template <class _Ret, class _Tp, class _Arg>
  454. class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
  455. typedef _Ret (_Tp::*__fun_type)(_Arg) const;
  456. public:
  457. explicit const_mem_fun1_t(__fun_type __pf) : _M_f(__pf) {}
  458. _Ret operator()(const _Tp* __p, _Arg __x) const
  459. { return (__p->*_M_f)(__x); }
  460. private:
  461. __fun_type _M_f;
  462. };
  463. template <class _Ret, class _Tp, class _Arg>
  464. class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
  465. typedef _Ret (_Tp::*__fun_type)(_Arg);
  466. public:
  467. explicit mem_fun1_ref_t(__fun_type __pf) : _M_f(__pf) {}
  468. _Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
  469. private:
  470. __fun_type _M_f;
  471. };
  472. template <class _Ret, class _Tp, class _Arg>
  473. class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
  474. typedef _Ret (_Tp::*__fun_type)(_Arg) const;
  475. public:
  476. explicit const_mem_fun1_ref_t(__fun_type __pf) : _M_f(__pf) {}
  477. _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
  478. private:
  479. __fun_type _M_f;
  480. };
  481. template <class _Arg, class _Result>
  482. class pointer_to_unary_function : public unary_function<_Arg, _Result> {
  483. protected:
  484. _Result (*_M_ptr)(_Arg);
  485. public:
  486. pointer_to_unary_function() {}
  487. explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {}
  488. _Result operator()(_Arg __x) const { return _M_ptr(__x); }
  489. };
  490. template <class _Arg1, class _Arg2, class _Result>
  491. class pointer_to_binary_function :
  492. public binary_function<_Arg1,_Arg2,_Result> {
  493. protected:
  494. _Result (*_M_ptr)(_Arg1, _Arg2);
  495. public:
  496. pointer_to_binary_function() {}
  497. explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
  498. : _M_ptr(__x) {}
  499. _Result operator()(_Arg1 __x, _Arg2 __y) const {
  500. return _M_ptr(__x, __y);
  501. }
  502. };
  503. # if defined (_STLP_DONT_RETURN_VOID) && !defined (_STLP_NO_CLASS_PARTIAL_SPECIALIZATION)
  504. //Partial specializations for the void type
  505. template <class _Tp>
  506. class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
  507. typedef void (_Tp::*__fun_type)(void);
  508. public:
  509. explicit mem_fun_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
  510. void operator()(_Tp* __p) const { (__p->*_M_f)(); }
  511. private:
  512. __fun_type _M_f;
  513. };
  514. template <class _Tp>
  515. class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
  516. typedef void (_Tp::*__fun_type)(void) const;
  517. public:
  518. explicit const_mem_fun_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
  519. void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
  520. private:
  521. __fun_type _M_f;
  522. };
  523. template <class _Tp>
  524. class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
  525. typedef void (_Tp::*__fun_type)(void);
  526. public:
  527. explicit mem_fun_ref_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
  528. void operator()(_Tp& __r) const { (__r.*_M_f)(); }
  529. private:
  530. __fun_type _M_f;
  531. };
  532. template <class _Tp>
  533. class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
  534. typedef void (_Tp::*__fun_type)(void) const;
  535. public:
  536. explicit const_mem_fun_ref_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
  537. void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
  538. private:
  539. __fun_type _M_f;
  540. };
  541. template <class _Tp, class _Arg>
  542. class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
  543. typedef void (_Tp::*__fun_type)(_Arg);
  544. public:
  545. explicit mem_fun1_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
  546. void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
  547. private:
  548. __fun_type _M_f;
  549. };
  550. template <class _Tp, class _Arg>
  551. class const_mem_fun1_t<void, _Tp, _Arg>
  552. : public binary_function<const _Tp*,_Arg,void> {
  553. typedef void (_Tp::*__fun_type)(_Arg) const;
  554. public:
  555. explicit const_mem_fun1_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
  556. void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
  557. private:
  558. __fun_type _M_f;
  559. };
  560. template <class _Tp, class _Arg>
  561. class mem_fun1_ref_t<void, _Tp, _Arg>
  562. : public binary_function<_Tp,_Arg,void> {
  563. typedef void (_Tp::*__fun_type)(_Arg);
  564. public:
  565. explicit mem_fun1_ref_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
  566. void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
  567. private:
  568. __fun_type _M_f;
  569. };
  570. template <class _Tp, class _Arg>
  571. class const_mem_fun1_ref_t<void, _Tp, _Arg>
  572. : public binary_function<_Tp,_Arg,void> {
  573. typedef void (_Tp::*__fun_type)(_Arg) const;
  574. public:
  575. explicit const_mem_fun1_ref_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
  576. void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
  577. private:
  578. __fun_type _M_f;
  579. };
  580. template <class _Arg>
  581. class pointer_to_unary_function<_Arg, void> : public unary_function<_Arg, void> {
  582. typedef void (*__fun_type)(_Arg);
  583. __fun_type _M_ptr;
  584. public:
  585. pointer_to_unary_function() {}
  586. explicit pointer_to_unary_function(__fun_type __x) : _M_ptr(__x) {}
  587. void operator()(_Arg __x) const { _M_ptr(__x); }
  588. };
  589. template <class _Arg1, class _Arg2>
  590. class pointer_to_binary_function<_Arg1, _Arg2, void> : public binary_function<_Arg1,_Arg2,void> {
  591. typedef void (*__fun_type)(_Arg1, _Arg2);
  592. __fun_type _M_ptr;
  593. public:
  594. pointer_to_binary_function() {}
  595. explicit pointer_to_binary_function(__fun_type __x) : _M_ptr(__x) {}
  596. void operator()(_Arg1 __x, _Arg2 __y) const { _M_ptr(__x, __y); }
  597. };
  598. # endif
  599. #endif
  600. #if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
  601. // Mem_fun adaptor helper functions. There are only two:
  602. // mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref
  603. // are provided for backward compatibility, but they are no longer
  604. // part of the C++ standard.)
  605. template <class _Result, class _Tp>
  606. inline mem_fun_t<_Result,_Tp>
  607. mem_fun(_Result (_Tp::*__f)()) { return mem_fun_t<_Result,_Tp>(__f); }
  608. template <class _Result, class _Tp>
  609. inline const_mem_fun_t<_Result,_Tp>
  610. mem_fun(_Result (_Tp::*__f)() const) { return const_mem_fun_t<_Result,_Tp>(__f); }
  611. template <class _Result, class _Tp>
  612. inline mem_fun_ref_t<_Result,_Tp>
  613. mem_fun_ref(_Result (_Tp::*__f)()) { return mem_fun_ref_t<_Result,_Tp>(__f); }
  614. template <class _Result, class _Tp>
  615. inline const_mem_fun_ref_t<_Result,_Tp>
  616. mem_fun_ref(_Result (_Tp::*__f)() const) { return const_mem_fun_ref_t<_Result,_Tp>(__f); }
  617. template <class _Result, class _Tp, class _Arg>
  618. inline mem_fun1_t<_Result,_Tp,_Arg>
  619. mem_fun(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_t<_Result,_Tp,_Arg>(__f); }
  620. template <class _Result, class _Tp, class _Arg>
  621. inline const_mem_fun1_t<_Result,_Tp,_Arg>
  622. mem_fun(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Result,_Tp,_Arg>(__f); }
  623. template <class _Result, class _Tp, class _Arg>
  624. inline mem_fun1_ref_t<_Result,_Tp,_Arg>
  625. mem_fun_ref(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }
  626. template <class _Result, class _Tp, class _Arg>
  627. inline const_mem_fun1_ref_t<_Result,_Tp,_Arg>
  628. mem_fun_ref(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }
  629. # if !(defined (_STLP_NO_EXTENSIONS) || defined (_STLP_NO_ANACHRONISMS))
  630. // mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,
  631. // but they are provided for backward compatibility.
  632. template <class _Result, class _Tp, class _Arg>
  633. inline mem_fun1_t<_Result,_Tp,_Arg>
  634. mem_fun1(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_t<_Result,_Tp,_Arg>(__f); }
  635. template <class _Result, class _Tp, class _Arg>
  636. inline const_mem_fun1_t<_Result,_Tp,_Arg>
  637. mem_fun1(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Result,_Tp,_Arg>(__f); }
  638. template <class _Result, class _Tp, class _Arg>
  639. inline mem_fun1_ref_t<_Result,_Tp,_Arg>
  640. mem_fun1_ref(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }
  641. template <class _Result, class _Tp, class _Arg>
  642. inline const_mem_fun1_ref_t<_Result,_Tp,_Arg>
  643. mem_fun1_ref(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }
  644. # endif
  645. #endif
  646. template <class _Arg, class _Result>
  647. inline pointer_to_unary_function<_Arg, _Result>
  648. ptr_fun(_Result (*__f)(_Arg))
  649. { return pointer_to_unary_function<_Arg, _Result>(__f); }
  650. template <class _Arg1, class _Arg2, class _Result>
  651. inline pointer_to_binary_function<_Arg1,_Arg2,_Result>
  652. ptr_fun(_Result (*__f)(_Arg1, _Arg2))
  653. { return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f); }
  654. _STLP_END_NAMESPACE