sl@0: #ifndef BOOST_MEM_FN_HPP_INCLUDED sl@0: #define BOOST_MEM_FN_HPP_INCLUDED sl@0: sl@0: // MS compatible compilers support #pragma once sl@0: sl@0: #if defined(_MSC_VER) && (_MSC_VER >= 1020) sl@0: # pragma once sl@0: #endif sl@0: sl@0: // sl@0: // mem_fn.hpp - a generalization of std::mem_fun[_ref] sl@0: // sl@0: // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. sl@0: // Copyright (c) 2001 David Abrahams sl@0: // Copyright (c) 2003-2005 Peter Dimov sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: // sl@0: // See http://www.boost.org/libs/bind/mem_fn.html for documentation. sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: namespace boost sl@0: { sl@0: sl@0: #if defined(BOOST_NO_VOID_RETURNS) sl@0: sl@0: #define BOOST_MEM_FN_CLASS_F , class F sl@0: #define BOOST_MEM_FN_TYPEDEF(X) sl@0: sl@0: namespace _mfi // mem_fun_impl sl@0: { sl@0: sl@0: template struct mf sl@0: { sl@0: sl@0: #define BOOST_MEM_FN_RETURN return sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) inner_##X sl@0: #define BOOST_MEM_FN_CC sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_CDECL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl sl@0: #define BOOST_MEM_FN_CC __cdecl sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_STDCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall sl@0: #define BOOST_MEM_FN_CC __stdcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_FASTCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall sl@0: #define BOOST_MEM_FN_CC __fastcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #undef BOOST_MEM_FN_RETURN sl@0: sl@0: }; // struct mf sl@0: sl@0: template<> struct mf sl@0: { sl@0: sl@0: #define BOOST_MEM_FN_RETURN sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) inner_##X sl@0: #define BOOST_MEM_FN_CC sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_CDECL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl sl@0: #define BOOST_MEM_FN_CC __cdecl sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_STDCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall sl@0: #define BOOST_MEM_FN_CC __stdcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_FASTCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall sl@0: #define BOOST_MEM_FN_CC __fastcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #undef BOOST_MEM_FN_RETURN sl@0: sl@0: }; // struct mf sl@0: sl@0: #undef BOOST_MEM_FN_CLASS_F sl@0: #undef BOOST_MEM_FN_TYPEDEF_F sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X sl@0: #define BOOST_MEM_FN_NAME2(X) inner_##X sl@0: #define BOOST_MEM_FN_CC sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_NAME sl@0: #undef BOOST_MEM_FN_NAME2 sl@0: #undef BOOST_MEM_FN_CC sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_CDECL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_cdecl sl@0: #define BOOST_MEM_FN_NAME2(X) inner_##X##_cdecl sl@0: #define BOOST_MEM_FN_CC __cdecl sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_NAME sl@0: #undef BOOST_MEM_FN_NAME2 sl@0: #undef BOOST_MEM_FN_CC sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_STDCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_stdcall sl@0: #define BOOST_MEM_FN_NAME2(X) inner_##X##_stdcall sl@0: #define BOOST_MEM_FN_CC __stdcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_NAME sl@0: #undef BOOST_MEM_FN_NAME2 sl@0: #undef BOOST_MEM_FN_CC sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_FASTCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_fastcall sl@0: #define BOOST_MEM_FN_NAME2(X) inner_##X##_fastcall sl@0: #define BOOST_MEM_FN_CC __fastcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_NAME sl@0: #undef BOOST_MEM_FN_NAME2 sl@0: #undef BOOST_MEM_FN_CC sl@0: sl@0: #endif sl@0: sl@0: } // namespace _mfi sl@0: sl@0: #else // #ifdef BOOST_NO_VOID_RETURNS sl@0: sl@0: #define BOOST_MEM_FN_CLASS_F sl@0: #define BOOST_MEM_FN_TYPEDEF(X) typedef X; sl@0: sl@0: namespace _mfi sl@0: { sl@0: sl@0: #define BOOST_MEM_FN_RETURN return sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X sl@0: #define BOOST_MEM_FN_CC sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_CDECL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_cdecl sl@0: #define BOOST_MEM_FN_CC __cdecl sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_STDCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_stdcall sl@0: #define BOOST_MEM_FN_CC __stdcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_FASTCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_fastcall sl@0: #define BOOST_MEM_FN_CC __fastcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_CC sl@0: #undef BOOST_MEM_FN_NAME sl@0: sl@0: #endif sl@0: sl@0: #undef BOOST_MEM_FN_RETURN sl@0: sl@0: } // namespace _mfi sl@0: sl@0: #undef BOOST_MEM_FN_CLASS_F sl@0: #undef BOOST_MEM_FN_TYPEDEF sl@0: sl@0: #endif // #ifdef BOOST_NO_VOID_RETURNS sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X sl@0: #define BOOST_MEM_FN_CC sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_NAME sl@0: #undef BOOST_MEM_FN_CC sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_CDECL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_cdecl sl@0: #define BOOST_MEM_FN_CC __cdecl sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_NAME sl@0: #undef BOOST_MEM_FN_CC sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_STDCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_stdcall sl@0: #define BOOST_MEM_FN_CC __stdcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_NAME sl@0: #undef BOOST_MEM_FN_CC sl@0: sl@0: #endif sl@0: sl@0: #ifdef BOOST_MEM_FN_ENABLE_FASTCALL sl@0: sl@0: #define BOOST_MEM_FN_NAME(X) X##_fastcall sl@0: #define BOOST_MEM_FN_CC __fastcall sl@0: sl@0: #include sl@0: sl@0: #undef BOOST_MEM_FN_NAME sl@0: #undef BOOST_MEM_FN_CC sl@0: sl@0: #endif sl@0: sl@0: // data member support sl@0: sl@0: namespace _mfi sl@0: { sl@0: sl@0: template class dm sl@0: { sl@0: public: sl@0: sl@0: typedef R const & result_type; sl@0: typedef T const * argument_type; sl@0: sl@0: private: sl@0: sl@0: typedef R (T::*F); sl@0: F f_; sl@0: sl@0: template R const & call(U & u, T const *) const sl@0: { sl@0: return (u.*f_); sl@0: } sl@0: sl@0: template R const & call(U & u, void const *) const sl@0: { sl@0: return (get_pointer(u)->*f_); sl@0: } sl@0: sl@0: public: sl@0: sl@0: explicit dm(F f): f_(f) {} sl@0: sl@0: R & operator()(T * p) const sl@0: { sl@0: return (p->*f_); sl@0: } sl@0: sl@0: R const & operator()(T const * p) const sl@0: { sl@0: return (p->*f_); sl@0: } sl@0: sl@0: template R const & operator()(U const & u) const sl@0: { sl@0: return call(u, &u); sl@0: } sl@0: sl@0: #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && !BOOST_WORKAROUND(__MWERKS__, < 0x3200) sl@0: sl@0: R & operator()(T & t) const sl@0: { sl@0: return (t.*f_); sl@0: } sl@0: sl@0: R const & operator()(T const & t) const sl@0: { sl@0: return (t.*f_); sl@0: } sl@0: sl@0: #endif sl@0: sl@0: bool operator==(dm const & rhs) const sl@0: { sl@0: return f_ == rhs.f_; sl@0: } sl@0: sl@0: bool operator!=(dm const & rhs) const sl@0: { sl@0: return f_ != rhs.f_; sl@0: } sl@0: }; sl@0: sl@0: } // namespace _mfi sl@0: sl@0: template _mfi::dm mem_fn(R T::*f) sl@0: { sl@0: return _mfi::dm(f); sl@0: } sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED