mem_fn.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. #ifndef BOOST_BIND_MEM_FN_HPP_INCLUDED
  2. #define BOOST_BIND_MEM_FN_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. //
  8. // mem_fn.hpp - a generalization of std::mem_fun[_ref]
  9. //
  10. // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
  11. // Copyright (c) 2001 David Abrahams
  12. // Copyright (c) 2003-2005 Peter Dimov
  13. //
  14. // Distributed under the Boost Software License, Version 1.0. (See
  15. // accompanying file LICENSE_1_0.txt or copy at
  16. // http://www.boost.org/LICENSE_1_0.txt)
  17. //
  18. // See http://www.boost.org/libs/bind/mem_fn.html for documentation.
  19. //
  20. #include <boost/config.hpp>
  21. #include <boost/get_pointer.hpp>
  22. #include <boost/detail/workaround.hpp>
  23. namespace boost
  24. {
  25. #if defined(BOOST_NO_VOID_RETURNS)
  26. #define BOOST_MEM_FN_CLASS_F , class F
  27. #define BOOST_MEM_FN_TYPEDEF(X)
  28. namespace _mfi // mem_fun_impl
  29. {
  30. template<class V> struct mf
  31. {
  32. #define BOOST_MEM_FN_RETURN return
  33. #define BOOST_MEM_FN_NAME(X) inner_##X
  34. #define BOOST_MEM_FN_CC
  35. #include <boost/bind/mem_fn_template.hpp>
  36. #undef BOOST_MEM_FN_CC
  37. #undef BOOST_MEM_FN_NAME
  38. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  39. #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
  40. #define BOOST_MEM_FN_CC __cdecl
  41. #include <boost/bind/mem_fn_template.hpp>
  42. #undef BOOST_MEM_FN_CC
  43. #undef BOOST_MEM_FN_NAME
  44. #endif
  45. #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64)
  46. #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
  47. #define BOOST_MEM_FN_CC __stdcall
  48. #include <boost/bind/mem_fn_template.hpp>
  49. #undef BOOST_MEM_FN_CC
  50. #undef BOOST_MEM_FN_NAME
  51. #endif
  52. #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64)
  53. #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
  54. #define BOOST_MEM_FN_CC __fastcall
  55. #include <boost/bind/mem_fn_template.hpp>
  56. #undef BOOST_MEM_FN_CC
  57. #undef BOOST_MEM_FN_NAME
  58. #endif
  59. #undef BOOST_MEM_FN_RETURN
  60. }; // struct mf<V>
  61. template<> struct mf<void>
  62. {
  63. #define BOOST_MEM_FN_RETURN
  64. #define BOOST_MEM_FN_NAME(X) inner_##X
  65. #define BOOST_MEM_FN_CC
  66. #include <boost/bind/mem_fn_template.hpp>
  67. #undef BOOST_MEM_FN_CC
  68. #undef BOOST_MEM_FN_NAME
  69. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  70. #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
  71. #define BOOST_MEM_FN_CC __cdecl
  72. #include <boost/bind/mem_fn_template.hpp>
  73. #undef BOOST_MEM_FN_CC
  74. #undef BOOST_MEM_FN_NAME
  75. #endif
  76. #ifdef BOOST_MEM_FN_ENABLE_STDCALL
  77. #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
  78. #define BOOST_MEM_FN_CC __stdcall
  79. #include <boost/bind/mem_fn_template.hpp>
  80. #undef BOOST_MEM_FN_CC
  81. #undef BOOST_MEM_FN_NAME
  82. #endif
  83. #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
  84. #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
  85. #define BOOST_MEM_FN_CC __fastcall
  86. #include <boost/bind/mem_fn_template.hpp>
  87. #undef BOOST_MEM_FN_CC
  88. #undef BOOST_MEM_FN_NAME
  89. #endif
  90. #undef BOOST_MEM_FN_RETURN
  91. }; // struct mf<void>
  92. #undef BOOST_MEM_FN_CLASS_F
  93. #undef BOOST_MEM_FN_TYPEDEF_F
  94. #define BOOST_MEM_FN_NAME(X) X
  95. #define BOOST_MEM_FN_NAME2(X) inner_##X
  96. #define BOOST_MEM_FN_CC
  97. #include <boost/bind/mem_fn_vw.hpp>
  98. #undef BOOST_MEM_FN_NAME
  99. #undef BOOST_MEM_FN_NAME2
  100. #undef BOOST_MEM_FN_CC
  101. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  102. #define BOOST_MEM_FN_NAME(X) X##_cdecl
  103. #define BOOST_MEM_FN_NAME2(X) inner_##X##_cdecl
  104. #define BOOST_MEM_FN_CC __cdecl
  105. #include <boost/bind/mem_fn_vw.hpp>
  106. #undef BOOST_MEM_FN_NAME
  107. #undef BOOST_MEM_FN_NAME2
  108. #undef BOOST_MEM_FN_CC
  109. #endif
  110. #ifdef BOOST_MEM_FN_ENABLE_STDCALL
  111. #define BOOST_MEM_FN_NAME(X) X##_stdcall
  112. #define BOOST_MEM_FN_NAME2(X) inner_##X##_stdcall
  113. #define BOOST_MEM_FN_CC __stdcall
  114. #include <boost/bind/mem_fn_vw.hpp>
  115. #undef BOOST_MEM_FN_NAME
  116. #undef BOOST_MEM_FN_NAME2
  117. #undef BOOST_MEM_FN_CC
  118. #endif
  119. #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
  120. #define BOOST_MEM_FN_NAME(X) X##_fastcall
  121. #define BOOST_MEM_FN_NAME2(X) inner_##X##_fastcall
  122. #define BOOST_MEM_FN_CC __fastcall
  123. #include <boost/bind/mem_fn_vw.hpp>
  124. #undef BOOST_MEM_FN_NAME
  125. #undef BOOST_MEM_FN_NAME2
  126. #undef BOOST_MEM_FN_CC
  127. #endif
  128. } // namespace _mfi
  129. #else // #ifdef BOOST_NO_VOID_RETURNS
  130. #define BOOST_MEM_FN_CLASS_F
  131. #define BOOST_MEM_FN_TYPEDEF(X) typedef X;
  132. namespace _mfi
  133. {
  134. #define BOOST_MEM_FN_RETURN return
  135. #define BOOST_MEM_FN_NAME(X) X
  136. #define BOOST_MEM_FN_CC
  137. #include <boost/bind/mem_fn_template.hpp>
  138. #undef BOOST_MEM_FN_CC
  139. #undef BOOST_MEM_FN_NAME
  140. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  141. #define BOOST_MEM_FN_NAME(X) X##_cdecl
  142. #define BOOST_MEM_FN_CC __cdecl
  143. #include <boost/bind/mem_fn_template.hpp>
  144. #undef BOOST_MEM_FN_CC
  145. #undef BOOST_MEM_FN_NAME
  146. #endif
  147. #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64)
  148. #define BOOST_MEM_FN_NAME(X) X##_stdcall
  149. #define BOOST_MEM_FN_CC __stdcall
  150. #include <boost/bind/mem_fn_template.hpp>
  151. #undef BOOST_MEM_FN_CC
  152. #undef BOOST_MEM_FN_NAME
  153. #endif
  154. #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64)
  155. #define BOOST_MEM_FN_NAME(X) X##_fastcall
  156. #define BOOST_MEM_FN_CC __fastcall
  157. #include <boost/bind/mem_fn_template.hpp>
  158. #undef BOOST_MEM_FN_CC
  159. #undef BOOST_MEM_FN_NAME
  160. #endif
  161. #undef BOOST_MEM_FN_RETURN
  162. } // namespace _mfi
  163. #undef BOOST_MEM_FN_CLASS_F
  164. #undef BOOST_MEM_FN_TYPEDEF
  165. #endif // #ifdef BOOST_NO_VOID_RETURNS
  166. #define BOOST_MEM_FN_NAME(X) X
  167. #define BOOST_MEM_FN_CC
  168. #include <boost/bind/mem_fn_cc.hpp>
  169. #undef BOOST_MEM_FN_NAME
  170. #undef BOOST_MEM_FN_CC
  171. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  172. #define BOOST_MEM_FN_NAME(X) X##_cdecl
  173. #define BOOST_MEM_FN_CC __cdecl
  174. #include <boost/bind/mem_fn_cc.hpp>
  175. #undef BOOST_MEM_FN_NAME
  176. #undef BOOST_MEM_FN_CC
  177. #endif
  178. #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64)
  179. #define BOOST_MEM_FN_NAME(X) X##_stdcall
  180. #define BOOST_MEM_FN_CC __stdcall
  181. #include <boost/bind/mem_fn_cc.hpp>
  182. #undef BOOST_MEM_FN_NAME
  183. #undef BOOST_MEM_FN_CC
  184. #endif
  185. #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64)
  186. #define BOOST_MEM_FN_NAME(X) X##_fastcall
  187. #define BOOST_MEM_FN_CC __fastcall
  188. #include <boost/bind/mem_fn_cc.hpp>
  189. #undef BOOST_MEM_FN_NAME
  190. #undef BOOST_MEM_FN_CC
  191. #endif
  192. // data member support
  193. namespace _mfi
  194. {
  195. template<class R, class T> class dm
  196. {
  197. public:
  198. typedef R const & result_type;
  199. typedef T const * argument_type;
  200. private:
  201. typedef R (T::*F);
  202. F f_;
  203. template<class U> R const & call(U & u, T const *) const
  204. {
  205. return (u.*f_);
  206. }
  207. template<class U> R const & call(U & u, void const *) const
  208. {
  209. return (get_pointer(u)->*f_);
  210. }
  211. public:
  212. explicit dm(F f): f_(f) {}
  213. R & operator()(T * p) const
  214. {
  215. return (p->*f_);
  216. }
  217. R const & operator()(T const * p) const
  218. {
  219. return (p->*f_);
  220. }
  221. template<class U> R const & operator()(U const & u) const
  222. {
  223. return call(u, &u);
  224. }
  225. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && !BOOST_WORKAROUND(__MWERKS__, < 0x3200)
  226. R & operator()(T & t) const
  227. {
  228. return (t.*f_);
  229. }
  230. R const & operator()(T const & t) const
  231. {
  232. return (t.*f_);
  233. }
  234. #endif
  235. bool operator==(dm const & rhs) const
  236. {
  237. return f_ == rhs.f_;
  238. }
  239. bool operator!=(dm const & rhs) const
  240. {
  241. return f_ != rhs.f_;
  242. }
  243. };
  244. } // namespace _mfi
  245. template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
  246. {
  247. return _mfi::dm<R, T>(f);
  248. }
  249. } // namespace boost
  250. #endif // #ifndef BOOST_BIND_MEM_FN_HPP_INCLUDED