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.

541 lines
12 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/obsolete/functional.hpp
  3. *
  4. * Purpose: Mappings to stdlib string functions
  5. *
  6. * Created: 2nd December 2004
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2004-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file stlsoft/obsolete/functional.hpp
  40. ///
  41. /// Mappings to stdlib string functions
  42. */
  43. #ifndef STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_FUNCTIONAL
  44. #define STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_FUNCTIONAL
  45. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  46. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_FUNCTIONAL_MAJOR 2
  47. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_FUNCTIONAL_MINOR 0
  48. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_FUNCTIONAL_REVISION 2
  49. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_FUNCTIONAL_EDIT 17
  50. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  51. /* /////////////////////////////////////////////////////////////////////////
  52. * Compatibility
  53. */
  54. /*
  55. [Incompatibilies-start]
  56. STLSOFT_COMPILER_IS_WATCOM:
  57. [Incompatibilies-end]
  58. */
  59. /* /////////////////////////////////////////////////////////////////////////
  60. * Includes
  61. */
  62. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  63. # include <stlsoft/stlsoft.h>
  64. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  65. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ATTRIBUTE_HPP_GET_PTR
  66. # include <stlsoft/shims/attribute/get_ptr.hpp>
  67. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ATTRIBUTE_HPP_GET_PTR */
  68. #ifndef STLSOFT_INCL_FUNCTIONAL
  69. # define STLSOFT_INCL_FUNCTIONAL
  70. # include <functional>
  71. #endif /* !STLSOFT_INCL_FUNCTIONAL */
  72. /* /////////////////////////////////////////////////////////////////////////
  73. * Namespace
  74. */
  75. #ifndef _STLSOFT_NO_NAMESPACE
  76. namespace stlsoft
  77. {
  78. #endif /* _STLSOFT_NO_NAMESPACE */
  79. /* /////////////////////////////////////////////////////////////////////////
  80. * Functors
  81. */
  82. template< ss_typename_param_k R
  83. , ss_typename_param_k C
  84. >
  85. class mem_fun_t
  86. : public stlsoft_ns_qual_std(unary_function)<C *, R>
  87. {
  88. public:
  89. ss_explicit_k mem_fun_t(R (C::*PFn)())
  90. : m_pfn(PFn)
  91. {}
  92. public:
  93. R operator()(C *c) const
  94. {
  95. return invoke_(c);
  96. }
  97. template <ss_typename_param_k T1>
  98. R operator()(T1 &t1) const
  99. {
  100. return invoke_(::stlsoft::get_ptr(t1));
  101. }
  102. /// \name Implementation
  103. /// @{
  104. private:
  105. R invoke_(C *c) const
  106. {
  107. return (c->*m_pfn)();
  108. }
  109. // Members
  110. private:
  111. R (C::*m_pfn)();
  112. };
  113. template< ss_typename_param_k R
  114. , ss_typename_param_k C
  115. >
  116. class mem_fun_const_t
  117. : public stlsoft_ns_qual_std(unary_function)<C *, R>
  118. {
  119. public:
  120. ss_explicit_k mem_fun_const_t(R (C::*PFn)() const)
  121. : m_pfn(PFn)
  122. {}
  123. public:
  124. R operator()(C *c) const
  125. {
  126. return invoke_(c);
  127. }
  128. template <ss_typename_param_k T1>
  129. R operator()(T1 &t1) const
  130. {
  131. return invoke_(::stlsoft::get_ptr(t1));
  132. }
  133. /// \name Implementation
  134. /// @{
  135. private:
  136. R invoke_(C *c) const
  137. {
  138. return (c->*m_pfn)();
  139. }
  140. // Members
  141. private:
  142. R (C::*m_pfn)() const;
  143. };
  144. template< ss_typename_param_k C
  145. >
  146. class mem_fun_void_t
  147. : public stlsoft_ns_qual_std(unary_function)<C *, void>
  148. {
  149. public:
  150. ss_explicit_k mem_fun_void_t(void (C::*PFn)())
  151. : m_pfn(PFn)
  152. {}
  153. public:
  154. void operator()(C *c) const
  155. {
  156. invoke_(c);
  157. }
  158. template <ss_typename_param_k T1>
  159. void operator()(T1 &t1) const
  160. {
  161. invoke_(::stlsoft::get_ptr(t1));
  162. }
  163. /// \name Implementation
  164. /// @{
  165. private:
  166. void invoke_(C *c) const
  167. {
  168. (c->*m_pfn)();
  169. }
  170. // Members
  171. private:
  172. void (C::*m_pfn)();
  173. };
  174. template< ss_typename_param_k C
  175. >
  176. class mem_fun_void_const_t
  177. : public stlsoft_ns_qual_std(unary_function)<C const*, void>
  178. {
  179. public:
  180. ss_explicit_k mem_fun_void_const_t(void (C::*PFn)() const)
  181. : m_pfn(PFn)
  182. {}
  183. public:
  184. void operator()(C *c) const
  185. {
  186. invoke_(c);
  187. }
  188. template <ss_typename_param_k T1>
  189. void operator()(T1 &t1) const
  190. {
  191. invoke_(::stlsoft::get_ptr(t1));
  192. }
  193. /// \name Implementation
  194. /// @{
  195. private:
  196. void invoke_(C *c) const
  197. {
  198. (c->*m_pfn)();
  199. }
  200. // Members
  201. private:
  202. void (C::*m_pfn)() const;
  203. };
  204. template< ss_typename_param_k R
  205. , ss_typename_param_k C
  206. >
  207. inline mem_fun_t<R, C> mem_fun(R (C::*PFn)())
  208. {
  209. return (mem_fun_t<R, C>(PFn));
  210. }
  211. template< ss_typename_param_k C
  212. >
  213. inline mem_fun_void_t<C> mem_fun(void (C::*PFn)())
  214. {
  215. return (mem_fun_void_t<C>(PFn));
  216. }
  217. template< ss_typename_param_k C
  218. >
  219. inline mem_fun_void_t<C> mem_fun_void(void (C::*PFn)())
  220. {
  221. return (mem_fun_void_t<C>(PFn));
  222. }
  223. //#if defined(STLSOFT_COMPILER_IS_MSVC) && _MSC_VER < 1310
  224. template< ss_typename_param_k R
  225. , ss_typename_param_k C
  226. >
  227. inline mem_fun_const_t<R, C> mem_fun(R (C::*PFn)() const)
  228. {
  229. return (mem_fun_const_t<R, C>(PFn));
  230. }
  231. template< ss_typename_param_k R
  232. , ss_typename_param_k C
  233. >
  234. inline mem_fun_const_t<R, C> mem_fun_const(R (C::*PFn)() const)
  235. {
  236. return (mem_fun_const_t<R, C>(PFn));
  237. }
  238. template< ss_typename_param_k C
  239. >
  240. inline mem_fun_void_const_t<C> mem_fun(void (C::*PFn)() const)
  241. {
  242. return (mem_fun_void_const_t<C>(PFn));
  243. }
  244. template< ss_typename_param_k C
  245. >
  246. inline mem_fun_void_const_t<C> mem_fun_void_const(void (C::*PFn)() const)
  247. {
  248. return (mem_fun_void_const_t<C>(PFn));
  249. }
  250. //#endif /* STLSOFT_COMPILER_IS_MSVC && _MSC_VER < 1310 */
  251. template< ss_typename_param_k R
  252. , ss_typename_param_k C
  253. , ss_typename_param_k A
  254. >
  255. class mem_fun1_t
  256. : public stlsoft_ns_qual_std(binary_function)<C *, A, R>
  257. {
  258. public:
  259. ss_explicit_k mem_fun1_t(R (C::*PFn)(A))
  260. : m_pfn(PFn)
  261. {}
  262. public:
  263. R operator()(C *c, A a0) const
  264. {
  265. return (c->*m_pfn)(a0);
  266. }
  267. private:
  268. R (C::*m_pfn)(A);
  269. };
  270. template< ss_typename_param_k R
  271. , ss_typename_param_k C
  272. , ss_typename_param_k A
  273. >
  274. inline mem_fun1_t<R, C, A> mem_fun1(R (C::*PFn)(A))
  275. {
  276. return (mem_fun1_t<R, C, A>(PFn));
  277. }
  278. template< ss_typename_param_k R
  279. , ss_typename_param_k C
  280. >
  281. class mem_fun_ref_t
  282. : public stlsoft_ns_qual_std(unary_function)<C, R>
  283. {
  284. public:
  285. ss_explicit_k mem_fun_ref_t(R (C::*PFn)())
  286. : m_pfn(PFn)
  287. {}
  288. public:
  289. R operator()(C &c) const
  290. {
  291. return (c.*m_pfn)();
  292. }
  293. private:
  294. R (C::*m_pfn)();
  295. };
  296. template< ss_typename_param_k R
  297. , ss_typename_param_k C
  298. >
  299. class mem_fun_ref_const_t
  300. : public stlsoft_ns_qual_std(unary_function)<C, R>
  301. {
  302. public:
  303. ss_explicit_k mem_fun_ref_const_t(R (C::*PFn)() const)
  304. : m_pfn(PFn)
  305. {}
  306. public:
  307. R operator()(C &c) const
  308. {
  309. return (c.*m_pfn)();
  310. }
  311. private:
  312. R (C::*m_pfn)() const;
  313. };
  314. template< ss_typename_param_k C
  315. >
  316. class mem_fun_ref_void_t
  317. : public stlsoft_ns_qual_std(unary_function)<C, void>
  318. {
  319. public:
  320. ss_explicit_k mem_fun_ref_void_t(void (C::*PFn)())
  321. : m_pfn(PFn)
  322. {}
  323. public:
  324. void operator()(C &c) const
  325. {
  326. (c.*m_pfn)();
  327. }
  328. private:
  329. void (C::*m_pfn)();
  330. };
  331. template< ss_typename_param_k C
  332. >
  333. class mem_fun_ref_void_const_t
  334. : public stlsoft_ns_qual_std(unary_function)<C, void>
  335. {
  336. public:
  337. ss_explicit_k mem_fun_ref_void_const_t(void (C::*PFn)() const)
  338. : m_pfn(PFn)
  339. {}
  340. public:
  341. void operator()(C &c) const
  342. {
  343. return (c.*m_pfn)();
  344. }
  345. private:
  346. void (C::*m_pfn)() const;
  347. };
  348. template< ss_typename_param_k R
  349. , ss_typename_param_k C
  350. >
  351. inline mem_fun_ref_t<R, C> mem_fun_ref(R (C::*PFn)())
  352. {
  353. return (mem_fun_ref_t<R, C>(PFn));
  354. }
  355. template< ss_typename_param_k C
  356. >
  357. inline mem_fun_ref_void_t<C> mem_fun_ref(void (C::*PFn)())
  358. {
  359. return (mem_fun_ref_void_t<C>(PFn));
  360. }
  361. template< ss_typename_param_k C
  362. >
  363. inline mem_fun_ref_void_t<C> mem_fun_ref_void(void (C::*PFn)())
  364. {
  365. return (mem_fun_ref_void_t<C>(PFn));
  366. }
  367. //#if defined(STLSOFT_COMPILER_IS_MSVC) && _MSC_VER < 1310
  368. template< ss_typename_param_k R
  369. , ss_typename_param_k C
  370. >
  371. inline mem_fun_ref_const_t<R, C> mem_fun_ref(R (C::*PFn)() const)
  372. {
  373. return (mem_fun_ref_const_t<R, C>(PFn));
  374. }
  375. template< ss_typename_param_k R
  376. , ss_typename_param_k C
  377. >
  378. inline mem_fun_ref_const_t<R, C> mem_fun_ref_const(R (C::*PFn)() const)
  379. {
  380. return (mem_fun_ref_const_t<R, C>(PFn));
  381. }
  382. template< ss_typename_param_k C
  383. >
  384. inline mem_fun_ref_void_const_t<C> mem_fun_ref(void (C::*PFn)() const)
  385. {
  386. return (mem_fun_ref_void_const_t<C>(PFn));
  387. }
  388. template< ss_typename_param_k C
  389. >
  390. inline mem_fun_ref_void_const_t<C> mem_fun_ref_void_const(void (C::*PFn)() const)
  391. {
  392. return (mem_fun_ref_void_const_t<C>(PFn));
  393. }
  394. //#endif /* STLSOFT_COMPILER_IS_MSVC && _MSC_VER < 1310 */
  395. template< ss_typename_param_k R
  396. , ss_typename_param_k C
  397. , ss_typename_param_k A
  398. >
  399. class mem_fun1_ref_t
  400. : public stlsoft_ns_qual_std(binary_function)<C *, A, R>
  401. {
  402. public:
  403. ss_explicit_k mem_fun1_ref_t(R (C::*PFn)(A))
  404. : m_pfn(PFn)
  405. {}
  406. public:
  407. R operator()(C &c, A a0) const
  408. {
  409. return (c.*m_pfn)(a0);
  410. }
  411. private:
  412. R (C::*m_pfn)(A);
  413. };
  414. template< ss_typename_param_k R
  415. , ss_typename_param_k C
  416. , ss_typename_param_k A
  417. >
  418. inline mem_fun1_ref_t<R, C, A> mem_fun1_ref(R (C::*PFn)(A))
  419. {
  420. return (mem_fun1_ref_t<R, C, A>(PFn));
  421. }
  422. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  423. /** \brief
  424. * \alpha
  425. *
  426. * \ingroup group__library__functional
  427. *
  428. * \note This is an alpha form, and *will* be changed in a future release
  429. */
  430. template< ss_typename_param_k R
  431. , ss_typename_param_k C
  432. , ss_typename_param_k V
  433. >
  434. // [[synesis:class:function-class:unary-function: mem_fun_ref_1_t<T<R>, T<C>, T<V>>]]
  435. struct mem_fun_ref_1_t
  436. {
  437. public:
  438. mem_fun_ref_1_t(R (C::*pfn)(V), V value)
  439. : m_pfn(pfn)
  440. , m_value(value)
  441. {}
  442. void operator ()(C &c)
  443. {
  444. (c.*m_pfn)(m_value);
  445. }
  446. private:
  447. R (C::*m_pfn)(V);
  448. V m_value;
  449. };
  450. template< ss_typename_param_k R
  451. , ss_typename_param_k C
  452. , ss_typename_param_k V
  453. >
  454. inline mem_fun_ref_1_t<R, C, V> mem_fun_ref_1(R (C::*pfn)(V), V value)
  455. {
  456. return mem_fun_ref_1_t<R, C, V>(pfn, value);
  457. }
  458. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  459. /* ////////////////////////////////////////////////////////////////////// */
  460. #ifndef _STLSOFT_NO_NAMESPACE
  461. } // namespace stlsoft
  462. #endif /* _STLSOFT_NO_NAMESPACE */
  463. /* ////////////////////////////////////////////////////////////////////// */
  464. #endif /* !STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_FUNCTIONAL */
  465. /* ///////////////////////////// end of file //////////////////////////// */