mirror of
https://github.com/boostorg/function.git
synced 2025-06-26 04:21:38 +02:00
Compare commits
10 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
fa7b9cbdfe | |||
1b60e82b2f | |||
7581949360 | |||
0b2aeda226 | |||
2ecd62c612 | |||
47033bd162 | |||
c7d5016022 | |||
d92355cca2 | |||
0123f84bff | |||
0207da8008 |
@ -10,8 +10,6 @@
|
||||
// William Kempf, Jesse Jones and Karl Nelson were all very helpful in the
|
||||
// design of this library.
|
||||
|
||||
#include <functional> // unary_function, binary_function
|
||||
|
||||
#include <boost/preprocessor/iterate.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
@ -23,8 +21,8 @@
|
||||
// in anything that may be included by function_template.hpp doesn't break
|
||||
#include <boost/function/detail/prologue.hpp>
|
||||
|
||||
// Visual Age C++ doesn't handle the file iteration well
|
||||
#if BOOST_WORKAROUND(__IBMCPP__, >= 500)
|
||||
// Older versions of the IBM C++ compiler do not handle file iterations well
|
||||
#if BOOST_WORKAROUND(__IBMCPP__, >= 500) && BOOST_WORKAROUND(__IBMCPP__, < 800)
|
||||
# if BOOST_FUNCTION_MAX_ARGS >= 0
|
||||
# include <boost/function/function0.hpp>
|
||||
# endif
|
||||
|
@ -11,7 +11,6 @@
|
||||
#define BOOST_FUNCTION_PROLOGUE_HPP
|
||||
# include <cassert>
|
||||
# include <algorithm>
|
||||
# include <functional> // unary_function, binary_function
|
||||
# include <boost/throw_exception.hpp>
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/function/function_base.hpp>
|
||||
|
@ -30,19 +30,6 @@
|
||||
#endif
|
||||
#include <boost/function_equal.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable : 4793 ) // complaint about native code generation
|
||||
#endif
|
||||
|
||||
// Define BOOST_FUNCTION_STD_NS to the namespace that contains type_info.
|
||||
#ifdef BOOST_NO_EXCEPTION_STD_NAMESPACE
|
||||
// Embedded VC++ does not have type_info in namespace std
|
||||
# define BOOST_FUNCTION_STD_NS
|
||||
#else
|
||||
# define BOOST_FUNCTION_STD_NS std
|
||||
#endif
|
||||
|
||||
// Borrowed from Boost.Python library: determines the cases where we
|
||||
// need to use std::type_info::name to compare instead of operator==.
|
||||
# if (defined(__GNUC__) && __GNUC__ >= 3) \
|
||||
@ -72,7 +59,7 @@ namespace boost { namespace python { namespace objects {
|
||||
|
||||
#if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
||||
|| defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) \
|
||||
|| !(defined(BOOST_STRICT_CONFIG) || !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540)
|
||||
|| !(BOOST_STRICT_CONFIG || !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540)
|
||||
# define BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
|
||||
#endif
|
||||
|
||||
@ -211,8 +198,8 @@ namespace boost {
|
||||
struct reference_manager
|
||||
{
|
||||
static inline void
|
||||
manage(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op)
|
||||
get(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op)
|
||||
{
|
||||
switch (op) {
|
||||
case clone_functor_tag:
|
||||
@ -228,8 +215,8 @@ namespace boost {
|
||||
// DPG TBD: Since we're only storing a pointer, it's
|
||||
// possible that the user could ask for a base class or
|
||||
// derived class. Is that okay?
|
||||
const BOOST_FUNCTION_STD_NS::type_info& check_type =
|
||||
*static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(out_buffer.const_obj_ptr);
|
||||
const std::type_info& check_type =
|
||||
*static_cast<const std::type_info*>(out_buffer.const_obj_ptr);
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, typeid(F)))
|
||||
out_buffer.obj_ptr = in_buffer.obj_ptr;
|
||||
else
|
||||
@ -278,8 +265,8 @@ namespace boost {
|
||||
else if (op == destroy_functor_tag)
|
||||
out_buffer.func_ptr = 0;
|
||||
else /* op == check_functor_type_tag */ {
|
||||
const BOOST_FUNCTION_STD_NS::type_info& check_type =
|
||||
*static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(out_buffer.const_obj_ptr);
|
||||
const std::type_info& check_type =
|
||||
*static_cast<const std::type_info*>(out_buffer.const_obj_ptr);
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, typeid(Functor)))
|
||||
out_buffer.obj_ptr = &in_buffer.func_ptr;
|
||||
else
|
||||
@ -300,8 +287,8 @@ namespace boost {
|
||||
// Some compilers (Borland, vc6, ...) are unhappy with ~functor_type.
|
||||
reinterpret_cast<functor_type*>(&out_buffer.data)->~Functor();
|
||||
} else /* op == check_functor_type_tag */ {
|
||||
const BOOST_FUNCTION_STD_NS::type_info& check_type =
|
||||
*static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(out_buffer.const_obj_ptr);
|
||||
const std::type_info& check_type =
|
||||
*static_cast<const std::type_info*>(out_buffer.const_obj_ptr);
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, typeid(Functor)))
|
||||
out_buffer.obj_ptr = &in_buffer.data;
|
||||
else
|
||||
@ -361,8 +348,8 @@ namespace boost {
|
||||
# endif // BOOST_NO_STD_ALLOCATOR
|
||||
out_buffer.obj_ptr = 0;
|
||||
} else /* op == check_functor_type_tag */ {
|
||||
const BOOST_FUNCTION_STD_NS::type_info& check_type =
|
||||
*static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(out_buffer.const_obj_ptr);
|
||||
const std::type_info& check_type =
|
||||
*static_cast<const std::type_info*>(out_buffer.const_obj_ptr);
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, typeid(Functor)))
|
||||
out_buffer.obj_ptr = in_buffer.obj_ptr;
|
||||
else
|
||||
@ -381,15 +368,6 @@ namespace boost {
|
||||
mpl::bool_<(function_allows_small_object_optimization<functor_type>::value)>());
|
||||
}
|
||||
|
||||
// For member pointers, we treat them as function objects with
|
||||
// the small-object optimization always enabled.
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, member_ptr_tag)
|
||||
{
|
||||
manager(in_buffer, out_buffer, op, mpl::true_());
|
||||
}
|
||||
|
||||
public:
|
||||
/* Dispatch to an appropriate manager based on whether we have a
|
||||
function pointer or a function object pointer. */
|
||||
@ -478,6 +456,7 @@ namespace boost {
|
||||
*/
|
||||
struct vtable_base
|
||||
{
|
||||
vtable_base() : manager(0) { }
|
||||
void (*manager)(const function_buffer& in_buffer,
|
||||
function_buffer& out_buffer,
|
||||
functor_manager_operation_type op);
|
||||
@ -501,13 +480,13 @@ public:
|
||||
|
||||
/** Retrieve the type of the stored function object, or typeid(void)
|
||||
if this is empty. */
|
||||
const BOOST_FUNCTION_STD_NS::type_info& target_type() const
|
||||
const std::type_info& target_type() const
|
||||
{
|
||||
if (!vtable) return typeid(void);
|
||||
|
||||
detail::function::function_buffer type;
|
||||
vtable->manager(functor, type, detail::function::get_functor_type_tag);
|
||||
return *static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(type.const_obj_ptr);
|
||||
return *static_cast<const std::type_info*>(type.const_obj_ptr);
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
@ -579,7 +558,7 @@ public:
|
||||
#endif
|
||||
|
||||
public: // should be protected, but GCC 2.95.3 will fail to allow access
|
||||
const detail::function::vtable_base* vtable;
|
||||
detail::function::vtable_base* vtable;
|
||||
mutable detail::function::function_buffer functor;
|
||||
};
|
||||
|
||||
@ -754,8 +733,4 @@ namespace detail {
|
||||
#undef BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL
|
||||
#undef BOOST_FUNCTION_COMPARE_TYPE_ID
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning( pop )
|
||||
#endif
|
||||
|
||||
#endif // BOOST_FUNCTION_BASE_HEADER
|
||||
|
@ -54,20 +54,12 @@
|
||||
BOOST_JOIN(function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER \
|
||||
BOOST_JOIN(void_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_MEMBER_INVOKER \
|
||||
BOOST_JOIN(member_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_VOID_MEMBER_INVOKER \
|
||||
BOOST_JOIN(void_member_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_GET_FUNCTION_INVOKER \
|
||||
BOOST_JOIN(get_function_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER \
|
||||
BOOST_JOIN(get_function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER \
|
||||
BOOST_JOIN(get_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_GET_MEMBER_INVOKER \
|
||||
BOOST_JOIN(get_member_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_GET_INVOKER \
|
||||
BOOST_JOIN(get_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
#define BOOST_FUNCTION_VTABLE BOOST_JOIN(basic_vtable,BOOST_FUNCTION_NUM_ARGS)
|
||||
|
||||
#ifndef BOOST_NO_VOID_RETURNS
|
||||
@ -78,6 +70,16 @@
|
||||
# define BOOST_FUNCTION_RETURN(X) X; return BOOST_FUNCTION_VOID_RETURN_TYPE ()
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4127) // conditional expression is constant.
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4127) // conditional expression is constant.
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
namespace function {
|
||||
@ -189,44 +191,6 @@ namespace boost {
|
||||
}
|
||||
};
|
||||
|
||||
#if BOOST_FUNCTION_NUM_ARGS > 0
|
||||
/* Handle invocation of member pointers. */
|
||||
template<
|
||||
typename MemberPtr,
|
||||
typename R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_PARMS
|
||||
>
|
||||
struct BOOST_FUNCTION_MEMBER_INVOKER
|
||||
{
|
||||
static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
MemberPtr* f =
|
||||
reinterpret_cast<MemberPtr*>(&function_obj_ptr.data);
|
||||
return boost::mem_fn(*f)(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename MemberPtr,
|
||||
typename R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_PARMS
|
||||
>
|
||||
struct BOOST_FUNCTION_VOID_MEMBER_INVOKER
|
||||
{
|
||||
static BOOST_FUNCTION_VOID_RETURN_TYPE
|
||||
invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
MemberPtr* f =
|
||||
reinterpret_cast<MemberPtr*>(&function_obj_ptr.data);
|
||||
BOOST_FUNCTION_RETURN(boost::mem_fn(*f)(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template<
|
||||
typename FunctionPtr,
|
||||
typename R BOOST_FUNCTION_COMMA
|
||||
@ -290,130 +254,12 @@ namespace boost {
|
||||
>::type type;
|
||||
};
|
||||
|
||||
#if BOOST_FUNCTION_NUM_ARGS > 0
|
||||
/* Retrieve the appropriate invoker for a member pointer. */
|
||||
template<
|
||||
typename MemberPtr,
|
||||
typename R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_PARMS
|
||||
>
|
||||
struct BOOST_FUNCTION_GET_MEMBER_INVOKER
|
||||
{
|
||||
typedef typename mpl::if_c<(is_void<R>::value),
|
||||
BOOST_FUNCTION_VOID_MEMBER_INVOKER<
|
||||
MemberPtr,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>,
|
||||
BOOST_FUNCTION_MEMBER_INVOKER<
|
||||
MemberPtr,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>
|
||||
>::type type;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Given the tag returned by get_function_tag, retrieve the
|
||||
actual invoker that will be used for the given function
|
||||
object.
|
||||
|
||||
Each specialization contains an "apply" nested class template
|
||||
that accepts the function object, return type, function
|
||||
argument types, and allocator. The resulting "apply" class
|
||||
contains two typedefs, "invoker_type" and "manager_type",
|
||||
which correspond to the invoker and manager types. */
|
||||
template<typename Tag>
|
||||
struct BOOST_FUNCTION_GET_INVOKER { };
|
||||
|
||||
/* Retrieve the invoker for a function pointer. */
|
||||
template<>
|
||||
struct BOOST_FUNCTION_GET_INVOKER<function_ptr_tag>
|
||||
{
|
||||
template<typename FunctionPtr,
|
||||
typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
|
||||
typename Allocator>
|
||||
struct apply
|
||||
{
|
||||
typedef typename BOOST_FUNCTION_GET_FUNCTION_INVOKER<
|
||||
FunctionPtr,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>::type
|
||||
invoker_type;
|
||||
|
||||
typedef functor_manager<FunctionPtr, Allocator> manager_type;
|
||||
};
|
||||
};
|
||||
|
||||
#if BOOST_FUNCTION_NUM_ARGS > 0
|
||||
/* Retrieve the invoker for a member pointer. */
|
||||
template<>
|
||||
struct BOOST_FUNCTION_GET_INVOKER<member_ptr_tag>
|
||||
{
|
||||
template<typename MemberPtr,
|
||||
typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
|
||||
typename Allocator>
|
||||
struct apply
|
||||
{
|
||||
typedef typename BOOST_FUNCTION_GET_MEMBER_INVOKER<
|
||||
MemberPtr,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>::type
|
||||
invoker_type;
|
||||
|
||||
typedef functor_manager<MemberPtr, Allocator> manager_type;
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Retrieve the invoker for a function object. */
|
||||
template<>
|
||||
struct BOOST_FUNCTION_GET_INVOKER<function_obj_tag>
|
||||
{
|
||||
template<typename FunctionObj,
|
||||
typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
|
||||
typename Allocator>
|
||||
struct apply
|
||||
{
|
||||
typedef typename BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER<
|
||||
FunctionObj,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>::type
|
||||
invoker_type;
|
||||
|
||||
typedef functor_manager<FunctionObj, Allocator> manager_type;
|
||||
};
|
||||
};
|
||||
|
||||
/* Retrieve the invoker for a reference to a function object. */
|
||||
template<>
|
||||
struct BOOST_FUNCTION_GET_INVOKER<function_obj_ref_tag>
|
||||
{
|
||||
template<typename RefWrapper,
|
||||
typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
|
||||
typename Allocator>
|
||||
struct apply
|
||||
{
|
||||
typedef typename BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER<
|
||||
typename RefWrapper::type,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>::type
|
||||
invoker_type;
|
||||
|
||||
typedef reference_manager<typename RefWrapper::type> manager_type;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* vtable for a specific boost::function instance.
|
||||
*/
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
|
||||
typename Allocator>
|
||||
struct BOOST_FUNCTION_VTABLE
|
||||
struct BOOST_FUNCTION_VTABLE : vtable_base
|
||||
{
|
||||
#ifndef BOOST_NO_VOID_RETURNS
|
||||
typedef R result_type;
|
||||
@ -426,25 +272,50 @@ namespace boost {
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS);
|
||||
|
||||
template<typename F>
|
||||
bool assign_to(const F& f, function_buffer& functor) const
|
||||
BOOST_FUNCTION_VTABLE(F f) : vtable_base(), invoker(0)
|
||||
{
|
||||
init(f);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
bool assign_to(F f, function_buffer& functor)
|
||||
{
|
||||
typedef typename get_function_tag<F>::type tag;
|
||||
return assign_to(f, functor, tag());
|
||||
}
|
||||
|
||||
void clear(function_buffer& functor) const
|
||||
void clear(function_buffer& functor)
|
||||
{
|
||||
if (base.manager)
|
||||
base.manager(functor, functor, destroy_functor_tag);
|
||||
if (manager)
|
||||
manager(functor, functor, destroy_functor_tag);
|
||||
}
|
||||
#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
|
||||
|
||||
private:
|
||||
#endif
|
||||
template<typename F>
|
||||
void init(F f)
|
||||
{
|
||||
typedef typename get_function_tag<F>::type tag;
|
||||
init(f, tag());
|
||||
}
|
||||
|
||||
// Function pointers
|
||||
template<typename FunctionPtr>
|
||||
void init(FunctionPtr /*f*/, function_ptr_tag)
|
||||
{
|
||||
typedef typename BOOST_FUNCTION_GET_FUNCTION_INVOKER<
|
||||
FunctionPtr,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>::type
|
||||
actual_invoker_type;
|
||||
|
||||
invoker = &actual_invoker_type::invoke;
|
||||
manager = &functor_manager<FunctionPtr, Allocator>::manage;
|
||||
}
|
||||
|
||||
template<typename FunctionPtr>
|
||||
bool
|
||||
assign_to(FunctionPtr f, function_buffer& functor,
|
||||
function_ptr_tag) const
|
||||
assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag)
|
||||
{
|
||||
this->clear(functor);
|
||||
if (f) {
|
||||
@ -460,13 +331,22 @@ namespace boost {
|
||||
// Member pointers
|
||||
#if BOOST_FUNCTION_NUM_ARGS > 0
|
||||
template<typename MemberPtr>
|
||||
bool
|
||||
assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag) const
|
||||
void init(MemberPtr f, member_ptr_tag)
|
||||
{
|
||||
// DPG TBD: Add explicit support for member function
|
||||
// objects, so we invoke through mem_fn() but we retain the
|
||||
// right target_type() values.
|
||||
this->init(mem_fn(f));
|
||||
}
|
||||
|
||||
template<typename MemberPtr>
|
||||
bool assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag)
|
||||
{
|
||||
// DPG TBD: Add explicit support for member function
|
||||
// objects, so we invoke through mem_fn() but we retain the
|
||||
// right target_type() values.
|
||||
if (f) {
|
||||
// Always use the small-object optimization for member
|
||||
// pointers.
|
||||
assign_functor(f, functor, mpl::true_());
|
||||
this->assign_to(mem_fn(f), functor);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -475,11 +355,24 @@ namespace boost {
|
||||
#endif // BOOST_FUNCTION_NUM_ARGS > 0
|
||||
|
||||
// Function objects
|
||||
template<typename FunctionObj>
|
||||
void init(FunctionObj /*f*/, function_obj_tag)
|
||||
{
|
||||
typedef typename BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER<
|
||||
FunctionObj,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>::type
|
||||
actual_invoker_type;
|
||||
|
||||
invoker = &actual_invoker_type::invoke;
|
||||
manager = &functor_manager<FunctionObj, Allocator>::manage;
|
||||
}
|
||||
|
||||
// Assign to a function object using the small object optimization
|
||||
template<typename FunctionObj>
|
||||
void
|
||||
assign_functor(const FunctionObj& f, function_buffer& functor,
|
||||
mpl::true_) const
|
||||
assign_functor(FunctionObj f, function_buffer& functor, mpl::true_)
|
||||
{
|
||||
new ((void*)&functor.data) FunctionObj(f);
|
||||
}
|
||||
@ -487,8 +380,7 @@ namespace boost {
|
||||
// Assign to a function object allocated on the heap.
|
||||
template<typename FunctionObj>
|
||||
void
|
||||
assign_functor(const FunctionObj& f, function_buffer& functor,
|
||||
mpl::false_) const
|
||||
assign_functor(FunctionObj f, function_buffer& functor, mpl::false_)
|
||||
{
|
||||
#ifndef BOOST_NO_STD_ALLOCATOR
|
||||
typedef typename Allocator::template rebind<FunctionObj>::other
|
||||
@ -508,8 +400,7 @@ namespace boost {
|
||||
|
||||
template<typename FunctionObj>
|
||||
bool
|
||||
assign_to(const FunctionObj& f, function_buffer& functor,
|
||||
function_obj_tag) const
|
||||
assign_to(FunctionObj f, function_buffer& functor, function_obj_tag)
|
||||
{
|
||||
if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
|
||||
assign_functor(f, functor,
|
||||
@ -521,10 +412,25 @@ namespace boost {
|
||||
}
|
||||
|
||||
// Reference to a function object
|
||||
template<typename FunctionObj>
|
||||
void
|
||||
init(const reference_wrapper<FunctionObj>& /*f*/, function_obj_ref_tag)
|
||||
{
|
||||
typedef typename BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER<
|
||||
FunctionObj,
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
>::type
|
||||
actual_invoker_type;
|
||||
|
||||
invoker = &actual_invoker_type::invoke;
|
||||
manager = &reference_manager<FunctionObj>::get;
|
||||
}
|
||||
|
||||
template<typename FunctionObj>
|
||||
bool
|
||||
assign_to(const reference_wrapper<FunctionObj>& f,
|
||||
function_buffer& functor, function_obj_ref_tag) const
|
||||
function_buffer& functor, function_obj_ref_tag)
|
||||
{
|
||||
if (!boost::detail::function::has_empty_target(f.get_pointer())) {
|
||||
// DPG TBD: We might need to detect constness of
|
||||
@ -539,7 +445,6 @@ namespace boost {
|
||||
}
|
||||
|
||||
public:
|
||||
vtable_base base;
|
||||
invoker_type invoker;
|
||||
};
|
||||
} // end namespace function
|
||||
@ -551,17 +456,6 @@ namespace boost {
|
||||
typename Allocator = BOOST_FUNCTION_DEFAULT_ALLOCATOR
|
||||
>
|
||||
class BOOST_FUNCTION_FUNCTION : public function_base
|
||||
|
||||
#if BOOST_FUNCTION_NUM_ARGS == 1
|
||||
|
||||
, public std::unary_function<T0,R>
|
||||
|
||||
#elif BOOST_FUNCTION_NUM_ARGS == 2
|
||||
|
||||
, public std::binary_function<T0,T1,R>
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_VOID_RETURNS
|
||||
@ -643,7 +537,7 @@ namespace boost {
|
||||
if (this->empty())
|
||||
boost::throw_exception(bad_function_call());
|
||||
|
||||
return reinterpret_cast<const vtable_type*>(vtable)->invoker
|
||||
return static_cast<vtable_type*>(vtable)->invoker
|
||||
(this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
#else
|
||||
@ -667,16 +561,12 @@ namespace boost {
|
||||
operator=(Functor BOOST_FUNCTION_TARGET_FIX(const &) f)
|
||||
{
|
||||
this->clear();
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try {
|
||||
this->assign_to(f);
|
||||
} catch (...) {
|
||||
vtable = 0;
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
this->assign_to(f);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -702,16 +592,12 @@ namespace boost {
|
||||
return *this;
|
||||
|
||||
this->clear();
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try {
|
||||
this->assign_to_own(f);
|
||||
} catch (...) {
|
||||
vtable = 0;
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
this->assign_to_own(f);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -729,7 +615,7 @@ namespace boost {
|
||||
void clear()
|
||||
{
|
||||
if (vtable) {
|
||||
reinterpret_cast<const vtable_type*>(vtable)->clear(this->functor);
|
||||
static_cast<vtable_type*>(vtable)->clear(this->functor);
|
||||
vtable = 0;
|
||||
}
|
||||
}
|
||||
@ -764,24 +650,10 @@ namespace boost {
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
void assign_to(const Functor& f)
|
||||
void assign_to(Functor f)
|
||||
{
|
||||
using detail::function::vtable_base;
|
||||
|
||||
typedef typename detail::function::get_function_tag<Functor>::type tag;
|
||||
typedef detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||
typedef typename get_invoker::
|
||||
template apply<Functor, R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS, Allocator>
|
||||
handler_type;
|
||||
|
||||
typedef typename handler_type::invoker_type invoker_type;
|
||||
typedef typename handler_type::manager_type manager_type;
|
||||
|
||||
static const vtable_type stored_vtable =
|
||||
{ { &manager_type::manage }, &invoker_type::invoke };
|
||||
|
||||
if (stored_vtable.assign_to(f, functor)) vtable = &stored_vtable.base;
|
||||
static vtable_type stored_vtable(f);
|
||||
if (stored_vtable.assign_to(f, functor)) vtable = &stored_vtable;
|
||||
else vtable = 0;
|
||||
}
|
||||
};
|
||||
@ -816,7 +688,7 @@ namespace boost {
|
||||
if (this->empty())
|
||||
boost::throw_exception(bad_function_call());
|
||||
|
||||
return reinterpret_cast<const vtable_type*>(vtable)->invoker
|
||||
return static_cast<vtable_type*>(vtable)->invoker
|
||||
(this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
#endif
|
||||
@ -926,14 +798,21 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#undef BOOST_FUNCTION_PARTIAL_SPEC
|
||||
#endif // have partial specialization
|
||||
|
||||
} // end namespace boost
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
// Cleanup after ourselves...
|
||||
#undef BOOST_FUNCTION_VTABLE
|
||||
#undef BOOST_FUNCTION_GET_INVOKER
|
||||
#undef BOOST_FUNCTION_DEFAULT_ALLOCATOR
|
||||
#undef BOOST_FUNCTION_COMMA
|
||||
#undef BOOST_FUNCTION_FUNCTION
|
||||
@ -943,12 +822,10 @@ public:
|
||||
#undef BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER
|
||||
#undef BOOST_FUNCTION_FUNCTION_REF_INVOKER
|
||||
#undef BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER
|
||||
#undef BOOST_FUNCTION_MEMBER_INVOKER
|
||||
#undef BOOST_FUNCTION_VOID_MEMBER_INVOKER
|
||||
#undef BOOST_FUNCTION_GET_FUNCTION_INVOKER
|
||||
#undef BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER
|
||||
#undef BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER
|
||||
#undef BOOST_FUNCTION_GET_MEMBER_INVOKER
|
||||
#undef BOOST_FUNCTION_GET_MEM_FUNCTION_INVOKER
|
||||
#undef BOOST_FUNCTION_TEMPLATE_PARMS
|
||||
#undef BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
#undef BOOST_FUNCTION_PARMS
|
||||
|
Reference in New Issue
Block a user