mem_fn.hpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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/bind/detail/requires_cxx11.hpp>
  21. #include <boost/get_pointer.hpp>
  22. #include <boost/config.hpp>
  23. #include <boost/config/workaround.hpp>
  24. namespace boost
  25. {
  26. #if defined(BOOST_NO_VOID_RETURNS)
  27. #define BOOST_MEM_FN_CLASS_F , class F
  28. #define BOOST_MEM_FN_TYPEDEF(X)
  29. namespace _mfi // mem_fun_impl
  30. {
  31. template<class V> struct mf
  32. {
  33. #define BOOST_MEM_FN_RETURN return
  34. #define BOOST_MEM_FN_NAME(X) inner_##X
  35. #define BOOST_MEM_FN_CC
  36. #include <boost/bind/mem_fn_template.hpp>
  37. #undef BOOST_MEM_FN_CC
  38. #undef BOOST_MEM_FN_NAME
  39. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  40. #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
  41. #define BOOST_MEM_FN_CC __cdecl
  42. #include <boost/bind/mem_fn_template.hpp>
  43. #undef BOOST_MEM_FN_CC
  44. #undef BOOST_MEM_FN_NAME
  45. #endif
  46. #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64)
  47. #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
  48. #define BOOST_MEM_FN_CC __stdcall
  49. #include <boost/bind/mem_fn_template.hpp>
  50. #undef BOOST_MEM_FN_CC
  51. #undef BOOST_MEM_FN_NAME
  52. #endif
  53. #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64)
  54. #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
  55. #define BOOST_MEM_FN_CC __fastcall
  56. #include <boost/bind/mem_fn_template.hpp>
  57. #undef BOOST_MEM_FN_CC
  58. #undef BOOST_MEM_FN_NAME
  59. #endif
  60. #undef BOOST_MEM_FN_RETURN
  61. }; // struct mf<V>
  62. template<> struct mf<void>
  63. {
  64. #define BOOST_MEM_FN_RETURN
  65. #define BOOST_MEM_FN_NAME(X) inner_##X
  66. #define BOOST_MEM_FN_CC
  67. #include <boost/bind/mem_fn_template.hpp>
  68. #undef BOOST_MEM_FN_CC
  69. #undef BOOST_MEM_FN_NAME
  70. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  71. #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
  72. #define BOOST_MEM_FN_CC __cdecl
  73. #include <boost/bind/mem_fn_template.hpp>
  74. #undef BOOST_MEM_FN_CC
  75. #undef BOOST_MEM_FN_NAME
  76. #endif
  77. #ifdef BOOST_MEM_FN_ENABLE_STDCALL
  78. #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
  79. #define BOOST_MEM_FN_CC __stdcall
  80. #include <boost/bind/mem_fn_template.hpp>
  81. #undef BOOST_MEM_FN_CC
  82. #undef BOOST_MEM_FN_NAME
  83. #endif
  84. #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
  85. #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
  86. #define BOOST_MEM_FN_CC __fastcall
  87. #include <boost/bind/mem_fn_template.hpp>
  88. #undef BOOST_MEM_FN_CC
  89. #undef BOOST_MEM_FN_NAME
  90. #endif
  91. #undef BOOST_MEM_FN_RETURN
  92. }; // struct mf<void>
  93. #undef BOOST_MEM_FN_CLASS_F
  94. #undef BOOST_MEM_FN_TYPEDEF_F
  95. #define BOOST_MEM_FN_NAME(X) X
  96. #define BOOST_MEM_FN_NAME2(X) inner_##X
  97. #define BOOST_MEM_FN_CC
  98. #include <boost/bind/mem_fn_vw.hpp>
  99. #undef BOOST_MEM_FN_NAME
  100. #undef BOOST_MEM_FN_NAME2
  101. #undef BOOST_MEM_FN_CC
  102. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  103. #define BOOST_MEM_FN_NAME(X) X##_cdecl
  104. #define BOOST_MEM_FN_NAME2(X) inner_##X##_cdecl
  105. #define BOOST_MEM_FN_CC __cdecl
  106. #include <boost/bind/mem_fn_vw.hpp>
  107. #undef BOOST_MEM_FN_NAME
  108. #undef BOOST_MEM_FN_NAME2
  109. #undef BOOST_MEM_FN_CC
  110. #endif
  111. #ifdef BOOST_MEM_FN_ENABLE_STDCALL
  112. #define BOOST_MEM_FN_NAME(X) X##_stdcall
  113. #define BOOST_MEM_FN_NAME2(X) inner_##X##_stdcall
  114. #define BOOST_MEM_FN_CC __stdcall
  115. #include <boost/bind/mem_fn_vw.hpp>
  116. #undef BOOST_MEM_FN_NAME
  117. #undef BOOST_MEM_FN_NAME2
  118. #undef BOOST_MEM_FN_CC
  119. #endif
  120. #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
  121. #define BOOST_MEM_FN_NAME(X) X##_fastcall
  122. #define BOOST_MEM_FN_NAME2(X) inner_##X##_fastcall
  123. #define BOOST_MEM_FN_CC __fastcall
  124. #include <boost/bind/mem_fn_vw.hpp>
  125. #undef BOOST_MEM_FN_NAME
  126. #undef BOOST_MEM_FN_NAME2
  127. #undef BOOST_MEM_FN_CC
  128. #endif
  129. } // namespace _mfi
  130. #else // #ifdef BOOST_NO_VOID_RETURNS
  131. #define BOOST_MEM_FN_CLASS_F
  132. #define BOOST_MEM_FN_TYPEDEF(X) typedef X;
  133. namespace _mfi
  134. {
  135. #define BOOST_MEM_FN_RETURN return
  136. #define BOOST_MEM_FN_NAME(X) X
  137. #define BOOST_MEM_FN_CC
  138. #include <boost/bind/mem_fn_template.hpp>
  139. #undef BOOST_MEM_FN_CC
  140. #undef BOOST_MEM_FN_NAME
  141. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  142. #define BOOST_MEM_FN_NAME(X) X##_cdecl
  143. #define BOOST_MEM_FN_CC __cdecl
  144. #include <boost/bind/mem_fn_template.hpp>
  145. #undef BOOST_MEM_FN_CC
  146. #undef BOOST_MEM_FN_NAME
  147. #endif
  148. #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64)
  149. #define BOOST_MEM_FN_NAME(X) X##_stdcall
  150. #define BOOST_MEM_FN_CC __stdcall
  151. #include <boost/bind/mem_fn_template.hpp>
  152. #undef BOOST_MEM_FN_CC
  153. #undef BOOST_MEM_FN_NAME
  154. #endif
  155. #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64)
  156. #define BOOST_MEM_FN_NAME(X) X##_fastcall
  157. #define BOOST_MEM_FN_CC __fastcall
  158. #include <boost/bind/mem_fn_template.hpp>
  159. #undef BOOST_MEM_FN_CC
  160. #undef BOOST_MEM_FN_NAME
  161. #endif
  162. #undef BOOST_MEM_FN_RETURN
  163. } // namespace _mfi
  164. #undef BOOST_MEM_FN_CLASS_F
  165. #undef BOOST_MEM_FN_TYPEDEF
  166. #endif // #ifdef BOOST_NO_VOID_RETURNS
  167. #define BOOST_MEM_FN_NAME(X) X
  168. #define BOOST_MEM_FN_CC
  169. #define BOOST_MEM_FN_NOEXCEPT
  170. #include <boost/bind/mem_fn_cc.hpp>
  171. #if defined( __cpp_noexcept_function_type ) || defined( _NOEXCEPT_TYPES_SUPPORTED )
  172. # undef BOOST_MEM_FN_NOEXCEPT
  173. # define BOOST_MEM_FN_NOEXCEPT noexcept
  174. # include <boost/bind/mem_fn_cc.hpp>
  175. #endif
  176. #undef BOOST_MEM_FN_NAME
  177. #undef BOOST_MEM_FN_CC
  178. #undef BOOST_MEM_FN_NOEXCEPT
  179. #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
  180. #define BOOST_MEM_FN_NAME(X) X##_cdecl
  181. #define BOOST_MEM_FN_CC __cdecl
  182. #define BOOST_MEM_FN_NOEXCEPT
  183. #include <boost/bind/mem_fn_cc.hpp>
  184. #undef BOOST_MEM_FN_NAME
  185. #undef BOOST_MEM_FN_CC
  186. #undef BOOST_MEM_FN_NOEXCEPT
  187. #endif
  188. #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64)
  189. #define BOOST_MEM_FN_NAME(X) X##_stdcall
  190. #define BOOST_MEM_FN_CC __stdcall
  191. #define BOOST_MEM_FN_NOEXCEPT
  192. #include <boost/bind/mem_fn_cc.hpp>
  193. #undef BOOST_MEM_FN_NAME
  194. #undef BOOST_MEM_FN_CC
  195. #undef BOOST_MEM_FN_NOEXCEPT
  196. #endif
  197. #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64)
  198. #define BOOST_MEM_FN_NAME(X) X##_fastcall
  199. #define BOOST_MEM_FN_CC __fastcall
  200. #define BOOST_MEM_FN_NOEXCEPT
  201. #include <boost/bind/mem_fn_cc.hpp>
  202. #undef BOOST_MEM_FN_NAME
  203. #undef BOOST_MEM_FN_CC
  204. #undef BOOST_MEM_FN_NOEXCEPT
  205. #endif
  206. // data member support
  207. namespace _mfi
  208. {
  209. template<class R, class T> class dm
  210. {
  211. public:
  212. typedef R const & result_type;
  213. typedef T const * argument_type;
  214. private:
  215. typedef R (T::*F);
  216. F f_;
  217. template<class U> R const & call(U & u, T const *) const
  218. {
  219. return (u.*f_);
  220. }
  221. template<class U> R const & call(U & u, void const *) const
  222. {
  223. return (get_pointer(u)->*f_);
  224. }
  225. public:
  226. explicit dm(F f): f_(f) {}
  227. R & operator()(T * p) const
  228. {
  229. return (p->*f_);
  230. }
  231. R const & operator()(T const * p) const
  232. {
  233. return (p->*f_);
  234. }
  235. template<class U> R const & operator()(U const & u) const
  236. {
  237. return call(u, &u);
  238. }
  239. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && !BOOST_WORKAROUND(__MWERKS__, < 0x3200)
  240. R & operator()(T & t) const
  241. {
  242. return (t.*f_);
  243. }
  244. R const & operator()(T const & t) const
  245. {
  246. return (t.*f_);
  247. }
  248. #endif
  249. bool operator==(dm const & rhs) const
  250. {
  251. return f_ == rhs.f_;
  252. }
  253. bool operator!=(dm const & rhs) const
  254. {
  255. return f_ != rhs.f_;
  256. }
  257. };
  258. } // namespace _mfi
  259. template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
  260. {
  261. return _mfi::dm<R, T>(f);
  262. }
  263. } // namespace boost
  264. #endif // #ifndef BOOST_BIND_MEM_FN_HPP_INCLUDED