mirror of
https://github.com/boostorg/function.git
synced 2025-07-23 09:27:14 +02:00
Added ability to handle member function pointers natively, e.g.,
boost::function<int, X*, int> f(&X::foo); [SVN r11393]
This commit is contained in:
@ -23,6 +23,7 @@
|
|||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/type_traits.hpp>
|
#include <boost/type_traits.hpp>
|
||||||
|
#include <boost/mem_fn.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@ -119,9 +120,23 @@ namespace boost {
|
|||||||
retrieve_type_info
|
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_ptr_tag {};
|
||||||
struct function_obj_tag {};
|
struct function_obj_tag {};
|
||||||
|
struct member_ptr_tag {};
|
||||||
|
|
||||||
|
template<typename F>
|
||||||
|
class get_function_tag
|
||||||
|
{
|
||||||
|
typedef typename IF<(is_pointer<F>::value),
|
||||||
|
function_ptr_tag,
|
||||||
|
function_obj_tag>::type ptr_or_obj_tag;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename IF<(is_member_pointer<F>::value),
|
||||||
|
member_ptr_tag,
|
||||||
|
ptr_or_obj_tag>::type type;
|
||||||
|
};
|
||||||
|
|
||||||
#ifndef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
|
#ifndef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
|
||||||
/**
|
/**
|
||||||
|
@ -664,9 +664,7 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
assert(typeid(To) != typeid(void));
|
assert(typeid(To) != typeid(void));
|
||||||
assert(typeid(To) == this->target_type());
|
assert(typeid(To) == this->target_type());
|
||||||
typedef typename detail::function::IF<(is_pointer<To>::value),
|
typedef typename detail::function::get_function_tag<To>::type tag;
|
||||||
detail::function::function_ptr_tag,
|
|
||||||
detail::function::function_obj_tag>::type tag;
|
|
||||||
|
|
||||||
#ifdef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
|
#ifdef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
|
||||||
impl_type* i = reinterpret_cast<impl_type*>(impl);
|
impl_type* i = reinterpret_cast<impl_type*>(impl);
|
||||||
@ -681,9 +679,7 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
assert(typeid(To) != typeid(void));
|
assert(typeid(To) != typeid(void));
|
||||||
assert(typeid(To) == this->target_type());
|
assert(typeid(To) == this->target_type());
|
||||||
typedef typename detail::function::IF<(is_pointer<To>::value),
|
typedef typename detail::function::get_function_tag<To>::type tag;
|
||||||
detail::function::function_ptr_tag,
|
|
||||||
detail::function::function_obj_tag>::type tag;
|
|
||||||
|
|
||||||
#ifdef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
|
#ifdef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
|
||||||
impl_type* i = reinterpret_cast<impl_type*>(impl);
|
impl_type* i = reinterpret_cast<impl_type*>(impl);
|
||||||
@ -727,12 +723,16 @@ namespace boost {
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
void assign_to(const Functor& f)
|
void assign_to(const Functor& f)
|
||||||
{
|
{
|
||||||
typedef typename detail::function::IF<(is_pointer<Functor>::value),
|
typedef typename detail::function::get_function_tag<Functor>::type tag;
|
||||||
detail::function::function_ptr_tag,
|
|
||||||
detail::function::function_obj_tag>::type tag;
|
|
||||||
this->assign_to(f, tag());
|
this->assign_to(f, tag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename MemberPtr>
|
||||||
|
void assign_to(MemberPtr f, detail::function::member_ptr_tag)
|
||||||
|
{
|
||||||
|
this->assign_to(mem_fn(f));
|
||||||
|
}
|
||||||
|
|
||||||
template<typename FunctionPtr>
|
template<typename FunctionPtr>
|
||||||
void assign_to(FunctionPtr f, detail::function::function_ptr_tag)
|
void assign_to(FunctionPtr f, detail::function::function_ptr_tag)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user