From 08d727df2138e9a77040db69a0e7628f76b63931 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 16 Oct 2001 19:23:37 +0000 Subject: [PATCH] Added ability to handle member function pointers natively, e.g., boost::function f(&X::foo); [SVN r11393] --- include/boost/function/function_base.hpp | 17 ++++++++++++++++- include/boost/function/function_template.hpp | 18 +++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/boost/function/function_base.hpp b/include/boost/function/function_base.hpp index 9b023e9..9a76da7 100644 --- a/include/boost/function/function_base.hpp +++ b/include/boost/function/function_base.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace boost { namespace detail { @@ -119,9 +120,23 @@ namespace boost { retrieve_type_info }; - // Tags used to decide between function and function object pointers. + // Tags used to decide between different types of functions struct function_ptr_tag {}; struct function_obj_tag {}; + struct member_ptr_tag {}; + + template + class get_function_tag + { + typedef typename IF<(is_pointer::value), + function_ptr_tag, + function_obj_tag>::type ptr_or_obj_tag; + + public: + typedef typename IF<(is_member_pointer::value), + member_ptr_tag, + ptr_or_obj_tag>::type type; + }; #ifndef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS /** diff --git a/include/boost/function/function_template.hpp b/include/boost/function/function_template.hpp index 26ab5e1..5de0be6 100644 --- a/include/boost/function/function_template.hpp +++ b/include/boost/function/function_template.hpp @@ -664,9 +664,7 @@ namespace boost { { assert(typeid(To) != typeid(void)); assert(typeid(To) == this->target_type()); - typedef typename detail::function::IF<(is_pointer::value), - detail::function::function_ptr_tag, - detail::function::function_obj_tag>::type tag; + typedef typename detail::function::get_function_tag::type tag; #ifdef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS impl_type* i = reinterpret_cast(impl); @@ -681,9 +679,7 @@ namespace boost { { assert(typeid(To) != typeid(void)); assert(typeid(To) == this->target_type()); - typedef typename detail::function::IF<(is_pointer::value), - detail::function::function_ptr_tag, - detail::function::function_obj_tag>::type tag; + typedef typename detail::function::get_function_tag::type tag; #ifdef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS impl_type* i = reinterpret_cast(impl); @@ -727,12 +723,16 @@ namespace boost { template void assign_to(const Functor& f) { - typedef typename detail::function::IF<(is_pointer::value), - detail::function::function_ptr_tag, - detail::function::function_obj_tag>::type tag; + typedef typename detail::function::get_function_tag::type tag; this->assign_to(f, tag()); } + template + void assign_to(MemberPtr f, detail::function::member_ptr_tag) + { + this->assign_to(mem_fn(f)); + } + template void assign_to(FunctionPtr f, detail::function::function_ptr_tag) {