2001-06-22 14:13:03 +00:00
|
|
|
// Boost.Function library
|
|
|
|
|
2006-01-10 23:52:35 +00:00
|
|
|
// Copyright Douglas Gregor 2001-2006. Use, modification and
|
2003-10-01 04:10:37 +00:00
|
|
|
// distribution is subject to the Boost Software License, Version
|
|
|
|
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
2001-06-21 16:19:33 +00:00
|
|
|
|
|
|
|
// For more information, see http://www.boost.org
|
|
|
|
|
2001-11-19 14:52:04 +00:00
|
|
|
// Note: this header is a header template and must NOT have multiple-inclusion
|
2002-09-24 19:52:56 +00:00
|
|
|
// protection.
|
2002-09-24 17:16:17 +00:00
|
|
|
#include <boost/function/detail/prologue.hpp>
|
2001-06-21 16:19:33 +00:00
|
|
|
|
2007-12-06 18:39:06 +00:00
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
# pragma warning( push )
|
|
|
|
# pragma warning( disable : 4127 ) // "conditional expression is constant"
|
|
|
|
#endif
|
|
|
|
|
2002-09-24 17:16:17 +00:00
|
|
|
#define BOOST_FUNCTION_TEMPLATE_PARMS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, typename T)
|
|
|
|
|
|
|
|
#define BOOST_FUNCTION_TEMPLATE_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, T)
|
|
|
|
|
|
|
|
#define BOOST_FUNCTION_PARM(J,I,D) BOOST_PP_CAT(T,I) BOOST_PP_CAT(a,I)
|
|
|
|
|
2002-09-25 03:30:18 +00:00
|
|
|
#define BOOST_FUNCTION_PARMS BOOST_PP_ENUM(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_PARM,BOOST_PP_EMPTY)
|
2002-09-24 17:16:17 +00:00
|
|
|
|
|
|
|
#define BOOST_FUNCTION_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, a)
|
|
|
|
|
|
|
|
#define BOOST_FUNCTION_ARG_TYPE(J,I,D) \
|
2005-12-18 21:06:32 +00:00
|
|
|
typedef BOOST_PP_CAT(T,I) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(I)),_type);
|
2002-09-24 17:16:17 +00:00
|
|
|
|
2002-09-24 19:52:56 +00:00
|
|
|
#define BOOST_FUNCTION_ARG_TYPES BOOST_PP_REPEAT(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_ARG_TYPE,BOOST_PP_EMPTY)
|
2001-06-21 16:19:33 +00:00
|
|
|
|
2001-10-06 20:28:27 +00:00
|
|
|
// Type of the default allocator
|
|
|
|
#ifndef BOOST_NO_STD_ALLOCATOR
|
|
|
|
# define BOOST_FUNCTION_DEFAULT_ALLOCATOR std::allocator<function_base>
|
|
|
|
#else
|
2001-10-08 13:49:02 +00:00
|
|
|
# define BOOST_FUNCTION_DEFAULT_ALLOCATOR int
|
2001-10-06 20:28:27 +00:00
|
|
|
#endif // BOOST_NO_STD_ALLOCATOR
|
|
|
|
|
2001-11-19 20:30:18 +00:00
|
|
|
// Comma if nonzero number of arguments
|
|
|
|
#if BOOST_FUNCTION_NUM_ARGS == 0
|
2002-09-24 19:52:56 +00:00
|
|
|
# define BOOST_FUNCTION_COMMA
|
2001-11-19 20:30:18 +00:00
|
|
|
#else
|
|
|
|
# define BOOST_FUNCTION_COMMA ,
|
|
|
|
#endif // BOOST_FUNCTION_NUM_ARGS > 0
|
|
|
|
|
|
|
|
// Class names used in this version of the code
|
|
|
|
#define BOOST_FUNCTION_FUNCTION BOOST_JOIN(function,BOOST_FUNCTION_NUM_ARGS)
|
|
|
|
#define BOOST_FUNCTION_FUNCTION_INVOKER \
|
|
|
|
BOOST_JOIN(function_invoker,BOOST_FUNCTION_NUM_ARGS)
|
|
|
|
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER \
|
2002-09-24 19:52:56 +00:00
|
|
|
BOOST_JOIN(void_function_invoker,BOOST_FUNCTION_NUM_ARGS)
|
2001-11-19 20:30:18 +00:00
|
|
|
#define BOOST_FUNCTION_FUNCTION_OBJ_INVOKER \
|
|
|
|
BOOST_JOIN(function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
|
|
|
|
#define BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER \
|
|
|
|
BOOST_JOIN(void_function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
|
2006-01-10 23:52:35 +00:00
|
|
|
#define BOOST_FUNCTION_FUNCTION_REF_INVOKER \
|
|
|
|
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)
|
2007-09-13 17:38:58 +00:00
|
|
|
#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)
|
2001-11-19 20:30:18 +00:00
|
|
|
#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)
|
2006-01-10 23:52:35 +00:00
|
|
|
#define BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER \
|
|
|
|
BOOST_JOIN(get_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
|
2007-09-13 17:38:58 +00:00
|
|
|
#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)
|
2005-12-30 02:31:51 +00:00
|
|
|
#define BOOST_FUNCTION_VTABLE BOOST_JOIN(basic_vtable,BOOST_FUNCTION_NUM_ARGS)
|
2001-11-19 20:30:18 +00:00
|
|
|
|
2004-12-15 21:40:30 +00:00
|
|
|
#ifndef BOOST_NO_VOID_RETURNS
|
|
|
|
# define BOOST_FUNCTION_VOID_RETURN_TYPE void
|
|
|
|
# define BOOST_FUNCTION_RETURN(X) X
|
|
|
|
#else
|
2005-08-24 14:12:03 +00:00
|
|
|
# define BOOST_FUNCTION_VOID_RETURN_TYPE boost::detail::function::unusable
|
2004-12-15 21:40:30 +00:00
|
|
|
# define BOOST_FUNCTION_RETURN(X) X; return BOOST_FUNCTION_VOID_RETURN_TYPE ()
|
|
|
|
#endif
|
|
|
|
|
2001-06-21 16:19:33 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace detail {
|
|
|
|
namespace function {
|
|
|
|
template<
|
|
|
|
typename FunctionPtr,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
|
|
|
struct BOOST_FUNCTION_FUNCTION_INVOKER
|
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
static R invoke(function_buffer& function_ptr BOOST_FUNCTION_COMMA
|
2001-06-21 16:19:33 +00:00
|
|
|
BOOST_FUNCTION_PARMS)
|
|
|
|
{
|
|
|
|
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
|
|
|
|
return f(BOOST_FUNCTION_ARGS);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename FunctionPtr,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
|
|
|
struct BOOST_FUNCTION_VOID_FUNCTION_INVOKER
|
|
|
|
{
|
2004-12-15 21:40:30 +00:00
|
|
|
static BOOST_FUNCTION_VOID_RETURN_TYPE
|
2006-01-10 23:52:35 +00:00
|
|
|
invoke(function_buffer& function_ptr BOOST_FUNCTION_COMMA
|
2004-12-15 21:40:30 +00:00
|
|
|
BOOST_FUNCTION_PARMS)
|
2002-01-30 15:04:08 +00:00
|
|
|
|
2001-06-21 16:19:33 +00:00
|
|
|
{
|
|
|
|
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
|
2004-12-15 21:40:30 +00:00
|
|
|
BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));
|
2001-06-21 16:19:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename FunctionObj,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
|
|
|
struct BOOST_FUNCTION_FUNCTION_OBJ_INVOKER
|
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
|
2001-06-21 16:19:33 +00:00
|
|
|
BOOST_FUNCTION_PARMS)
|
|
|
|
|
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
FunctionObj* f;
|
|
|
|
if (function_allows_small_object_optimization<FunctionObj>::value)
|
|
|
|
f = reinterpret_cast<FunctionObj*>(&function_obj_ptr.data);
|
|
|
|
else
|
|
|
|
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
2001-07-22 05:26:17 +00:00
|
|
|
return (*f)(BOOST_FUNCTION_ARGS);
|
2001-06-21 16:19:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename FunctionObj,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
|
|
|
struct BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER
|
|
|
|
{
|
2004-12-15 21:40:30 +00:00
|
|
|
static BOOST_FUNCTION_VOID_RETURN_TYPE
|
2006-01-10 23:52:35 +00:00
|
|
|
invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
|
2004-12-15 21:40:30 +00:00
|
|
|
BOOST_FUNCTION_PARMS)
|
2001-06-21 16:19:33 +00:00
|
|
|
|
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
FunctionObj* f;
|
|
|
|
if (function_allows_small_object_optimization<FunctionObj>::value)
|
|
|
|
f = reinterpret_cast<FunctionObj*>(&function_obj_ptr.data);
|
|
|
|
else
|
|
|
|
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
2004-12-15 21:40:30 +00:00
|
|
|
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
|
2001-06-21 16:19:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-01-30 01:59:49 +00:00
|
|
|
template<
|
|
|
|
typename FunctionObj,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
2006-01-10 23:52:35 +00:00
|
|
|
struct BOOST_FUNCTION_FUNCTION_REF_INVOKER
|
2002-01-30 01:59:49 +00:00
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_PARMS)
|
|
|
|
|
2002-01-30 01:59:49 +00:00
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
FunctionObj* f =
|
|
|
|
reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
|
|
|
return (*f)(BOOST_FUNCTION_ARGS);
|
2002-01-30 01:59:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename FunctionObj,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
2006-01-10 23:52:35 +00:00
|
|
|
struct BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER
|
2002-01-30 01:59:49 +00:00
|
|
|
{
|
2004-12-15 21:40:30 +00:00
|
|
|
static BOOST_FUNCTION_VOID_RETURN_TYPE
|
2006-01-10 23:52:35 +00:00
|
|
|
invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_PARMS)
|
2002-01-30 01:59:49 +00:00
|
|
|
|
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
FunctionObj* f =
|
|
|
|
reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
|
|
|
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
|
2002-01-30 01:59:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-09-13 17:38:58 +00:00
|
|
|
#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
|
|
|
|
|
2001-06-21 16:19:33 +00:00
|
|
|
template<
|
|
|
|
typename FunctionPtr,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
|
|
|
struct BOOST_FUNCTION_GET_FUNCTION_INVOKER
|
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
typedef typename mpl::if_c<(is_void<R>::value),
|
2001-06-21 16:19:33 +00:00
|
|
|
BOOST_FUNCTION_VOID_FUNCTION_INVOKER<
|
|
|
|
FunctionPtr,
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS
|
|
|
|
>,
|
|
|
|
BOOST_FUNCTION_FUNCTION_INVOKER<
|
|
|
|
FunctionPtr,
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS
|
|
|
|
>
|
|
|
|
>::type type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename FunctionObj,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
|
|
|
struct BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER
|
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
typedef typename mpl::if_c<(is_void<R>::value),
|
2001-06-21 16:19:33 +00:00
|
|
|
BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER<
|
|
|
|
FunctionObj,
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS
|
|
|
|
>,
|
|
|
|
BOOST_FUNCTION_FUNCTION_OBJ_INVOKER<
|
|
|
|
FunctionObj,
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS
|
|
|
|
>
|
|
|
|
>::type type;
|
|
|
|
};
|
2002-01-30 01:59:49 +00:00
|
|
|
|
|
|
|
template<
|
|
|
|
typename FunctionObj,
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
>
|
2006-01-10 23:52:35 +00:00
|
|
|
struct BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER
|
2002-01-30 01:59:49 +00:00
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
typedef typename mpl::if_c<(is_void<R>::value),
|
|
|
|
BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER<
|
2002-01-30 01:59:49 +00:00
|
|
|
FunctionObj,
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS
|
|
|
|
>,
|
2006-01-10 23:52:35 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION_REF_INVOKER<
|
2002-01-30 01:59:49 +00:00
|
|
|
FunctionObj,
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS
|
|
|
|
>
|
|
|
|
>::type type;
|
|
|
|
};
|
|
|
|
|
2007-09-13 17:38:58 +00:00
|
|
|
#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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2005-12-30 02:31:51 +00:00
|
|
|
/**
|
|
|
|
* vtable for a specific boost::function instance.
|
|
|
|
*/
|
|
|
|
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
|
|
|
|
typename Allocator>
|
2007-09-13 17:38:58 +00:00
|
|
|
struct BOOST_FUNCTION_VTABLE
|
2005-12-30 02:31:51 +00:00
|
|
|
{
|
|
|
|
#ifndef BOOST_NO_VOID_RETURNS
|
|
|
|
typedef R result_type;
|
|
|
|
#else
|
|
|
|
typedef typename function_return_type<R>::type result_type;
|
|
|
|
#endif // BOOST_NO_VOID_RETURNS
|
|
|
|
|
2006-01-10 23:52:35 +00:00
|
|
|
typedef result_type (*invoker_type)(function_buffer&
|
2005-12-30 02:31:51 +00:00
|
|
|
BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS);
|
|
|
|
|
|
|
|
template<typename F>
|
2007-09-13 19:06:53 +00:00
|
|
|
bool assign_to(const F& f, function_buffer& functor) const
|
2005-12-30 02:31:51 +00:00
|
|
|
{
|
|
|
|
typedef typename get_function_tag<F>::type tag;
|
|
|
|
return assign_to(f, functor, tag());
|
|
|
|
}
|
|
|
|
|
2007-09-13 17:38:58 +00:00
|
|
|
void clear(function_buffer& functor) const
|
2005-12-30 02:31:51 +00:00
|
|
|
{
|
2007-09-14 21:05:46 +00:00
|
|
|
if (base.manager)
|
|
|
|
base.manager(functor, functor, destroy_functor_tag);
|
2005-12-30 02:31:51 +00:00
|
|
|
}
|
2007-10-02 17:41:35 +00:00
|
|
|
#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
|
2005-12-30 02:31:51 +00:00
|
|
|
private:
|
2007-10-02 17:41:35 +00:00
|
|
|
#endif
|
2005-12-30 02:31:51 +00:00
|
|
|
// Function pointers
|
|
|
|
template<typename FunctionPtr>
|
2006-01-10 23:52:35 +00:00
|
|
|
bool
|
2007-09-13 17:38:58 +00:00
|
|
|
assign_to(FunctionPtr f, function_buffer& functor,
|
|
|
|
function_ptr_tag) const
|
2005-12-30 02:31:51 +00:00
|
|
|
{
|
|
|
|
this->clear(functor);
|
|
|
|
if (f) {
|
|
|
|
// should be a reinterpret cast, but some compilers insist
|
|
|
|
// on giving cv-qualifiers to free functions
|
2006-01-10 23:52:35 +00:00
|
|
|
functor.func_ptr = (void (*)())(f);
|
2005-12-30 02:31:51 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Member pointers
|
|
|
|
#if BOOST_FUNCTION_NUM_ARGS > 0
|
|
|
|
template<typename MemberPtr>
|
2007-09-13 17:38:58 +00:00
|
|
|
bool
|
|
|
|
assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag) const
|
2005-12-30 02:31:51 +00:00
|
|
|
{
|
|
|
|
if (f) {
|
2007-09-13 17:38:58 +00:00
|
|
|
// Always use the small-object optimization for member
|
|
|
|
// pointers.
|
|
|
|
assign_functor(f, functor, mpl::true_());
|
2005-12-30 02:31:51 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // BOOST_FUNCTION_NUM_ARGS > 0
|
|
|
|
|
2006-01-10 23:52:35 +00:00
|
|
|
// Function objects
|
|
|
|
// Assign to a function object using the small object optimization
|
2005-12-30 02:31:51 +00:00
|
|
|
template<typename FunctionObj>
|
2006-01-10 23:52:35 +00:00
|
|
|
void
|
2007-09-13 19:06:53 +00:00
|
|
|
assign_functor(const FunctionObj& f, function_buffer& functor,
|
2007-09-13 17:38:58 +00:00
|
|
|
mpl::true_) const
|
2006-01-10 23:52:35 +00:00
|
|
|
{
|
|
|
|
new ((void*)&functor.data) FunctionObj(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign to a function object allocated on the heap.
|
|
|
|
template<typename FunctionObj>
|
|
|
|
void
|
2007-09-13 19:06:53 +00:00
|
|
|
assign_functor(const FunctionObj& f, function_buffer& functor,
|
2007-09-13 17:38:58 +00:00
|
|
|
mpl::false_) const
|
2005-12-30 02:31:51 +00:00
|
|
|
{
|
|
|
|
#ifndef BOOST_NO_STD_ALLOCATOR
|
2006-01-10 23:52:35 +00:00
|
|
|
typedef typename Allocator::template rebind<FunctionObj>::other
|
|
|
|
allocator_type;
|
|
|
|
typedef typename allocator_type::pointer pointer_type;
|
|
|
|
|
|
|
|
allocator_type allocator;
|
|
|
|
pointer_type copy = allocator.allocate(1);
|
|
|
|
allocator.construct(copy, f);
|
|
|
|
|
|
|
|
// Get back to the original pointer type
|
|
|
|
functor.obj_ptr = static_cast<FunctionObj*>(copy);
|
|
|
|
# else
|
|
|
|
functor.obj_ptr = new FunctionObj(f);
|
|
|
|
# endif // BOOST_NO_STD_ALLOCATOR
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename FunctionObj>
|
|
|
|
bool
|
2007-09-13 19:06:53 +00:00
|
|
|
assign_to(const FunctionObj& f, function_buffer& functor,
|
2007-09-13 17:38:58 +00:00
|
|
|
function_obj_tag) const
|
2006-01-10 23:52:35 +00:00
|
|
|
{
|
|
|
|
if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
|
|
|
|
assign_functor(f, functor,
|
|
|
|
mpl::bool_<(function_allows_small_object_optimization<FunctionObj>::value)>());
|
2005-12-30 02:31:51 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reference to a function object
|
|
|
|
template<typename FunctionObj>
|
|
|
|
bool
|
2006-01-10 23:52:35 +00:00
|
|
|
assign_to(const reference_wrapper<FunctionObj>& f,
|
2007-09-13 17:38:58 +00:00
|
|
|
function_buffer& functor, function_obj_ref_tag) const
|
2005-12-30 02:31:51 +00:00
|
|
|
{
|
|
|
|
if (!boost::detail::function::has_empty_target(f.get_pointer())) {
|
2006-01-10 23:52:35 +00:00
|
|
|
// DPG TBD: We might need to detect constness of
|
|
|
|
// FunctionObj to assign into obj_ptr or const_obj_ptr to
|
|
|
|
// be truly legit, but no platform in existence makes
|
|
|
|
// const void* different from void*.
|
|
|
|
functor.const_obj_ptr = f.get_pointer();
|
2005-12-30 02:31:51 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2007-09-14 21:05:46 +00:00
|
|
|
vtable_base base;
|
2005-12-30 02:31:51 +00:00
|
|
|
invoker_type invoker;
|
|
|
|
};
|
2001-06-29 19:33:29 +00:00
|
|
|
} // end namespace function
|
|
|
|
} // end namespace detail
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS,
|
2001-10-06 20:28:27 +00:00
|
|
|
typename Allocator = BOOST_FUNCTION_DEFAULT_ALLOCATOR
|
2001-06-29 19:33:29 +00:00
|
|
|
>
|
2002-08-05 06:19:17 +00:00
|
|
|
class BOOST_FUNCTION_FUNCTION : public function_base
|
2006-07-08 18:07:33 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2001-06-29 19:33:29 +00:00
|
|
|
{
|
2003-07-18 16:18:16 +00:00
|
|
|
public:
|
2004-12-15 21:40:30 +00:00
|
|
|
#ifndef BOOST_NO_VOID_RETURNS
|
|
|
|
typedef R result_type;
|
|
|
|
#else
|
2005-08-24 14:12:03 +00:00
|
|
|
typedef typename boost::detail::function::function_return_type<R>::type
|
2004-12-15 21:40:30 +00:00
|
|
|
result_type;
|
|
|
|
#endif // BOOST_NO_VOID_RETURNS
|
2002-01-31 22:56:16 +00:00
|
|
|
|
2003-07-18 16:18:16 +00:00
|
|
|
private:
|
2005-12-30 02:31:51 +00:00
|
|
|
typedef boost::detail::function::BOOST_FUNCTION_VTABLE<
|
|
|
|
R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS, Allocator>
|
|
|
|
vtable_type;
|
|
|
|
|
2002-11-09 16:02:47 +00:00
|
|
|
struct clear_type {};
|
|
|
|
|
2001-07-14 18:41:19 +00:00
|
|
|
public:
|
|
|
|
BOOST_STATIC_CONSTANT(int, args = BOOST_FUNCTION_NUM_ARGS);
|
2002-09-24 19:52:56 +00:00
|
|
|
|
2002-11-04 18:19:01 +00:00
|
|
|
// add signature for boost::lambda
|
|
|
|
template<typename Args>
|
|
|
|
struct sig
|
|
|
|
{
|
2004-12-15 21:40:30 +00:00
|
|
|
typedef result_type type;
|
2002-11-04 18:19:01 +00:00
|
|
|
};
|
|
|
|
|
2001-07-14 18:41:19 +00:00
|
|
|
#if BOOST_FUNCTION_NUM_ARGS == 1
|
2001-11-19 20:30:18 +00:00
|
|
|
typedef T0 argument_type;
|
2001-07-14 18:41:19 +00:00
|
|
|
#elif BOOST_FUNCTION_NUM_ARGS == 2
|
2001-11-19 20:30:18 +00:00
|
|
|
typedef T0 first_argument_type;
|
|
|
|
typedef T1 second_argument_type;
|
2001-07-14 18:41:19 +00:00
|
|
|
#endif
|
2002-02-01 02:51:48 +00:00
|
|
|
|
2002-09-06 18:47:59 +00:00
|
|
|
BOOST_STATIC_CONSTANT(int, arity = BOOST_FUNCTION_NUM_ARGS);
|
|
|
|
BOOST_FUNCTION_ARG_TYPES
|
|
|
|
|
2001-07-14 18:41:19 +00:00
|
|
|
typedef Allocator allocator_type;
|
2001-07-14 19:34:14 +00:00
|
|
|
typedef BOOST_FUNCTION_FUNCTION self_type;
|
2001-06-29 19:33:29 +00:00
|
|
|
|
2005-12-30 02:31:51 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION() : function_base() { }
|
2001-09-18 14:48:51 +00:00
|
|
|
|
2001-07-14 19:34:14 +00:00
|
|
|
// MSVC chokes if the following two constructors are collapsed into
|
|
|
|
// one with a default parameter.
|
2001-06-29 19:33:29 +00:00
|
|
|
template<typename Functor>
|
2002-11-09 16:02:47 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f
|
2003-12-04 22:31:09 +00:00
|
|
|
#ifndef BOOST_NO_SFINAE
|
|
|
|
,typename enable_if_c<
|
2005-08-24 14:12:03 +00:00
|
|
|
(boost::type_traits::ice_not<
|
2003-09-10 04:16:17 +00:00
|
|
|
(is_integral<Functor>::value)>::value),
|
2002-11-09 16:02:47 +00:00
|
|
|
int>::type = 0
|
2003-12-04 22:31:09 +00:00
|
|
|
#endif // BOOST_NO_SFINAE
|
2002-11-09 16:02:47 +00:00
|
|
|
) :
|
2005-12-30 02:31:51 +00:00
|
|
|
function_base()
|
2001-06-29 19:33:29 +00:00
|
|
|
{
|
|
|
|
this->assign_to(f);
|
|
|
|
}
|
2001-06-21 16:19:33 +00:00
|
|
|
|
2003-12-04 22:31:09 +00:00
|
|
|
#ifndef BOOST_NO_SFINAE
|
2005-12-30 02:31:51 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION(clear_type*) : function_base() { }
|
2002-12-15 14:51:16 +00:00
|
|
|
#else
|
2005-12-30 02:31:51 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION(int zero) : function_base()
|
2002-12-15 14:54:32 +00:00
|
|
|
{
|
|
|
|
BOOST_ASSERT(zero == 0);
|
|
|
|
}
|
2002-12-15 14:51:16 +00:00
|
|
|
#endif
|
2002-11-09 16:02:47 +00:00
|
|
|
|
2005-12-30 02:31:51 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION(const BOOST_FUNCTION_FUNCTION& f) : function_base()
|
2001-06-21 16:19:33 +00:00
|
|
|
{
|
2001-06-29 19:33:29 +00:00
|
|
|
this->assign_to_own(f);
|
2001-06-21 16:19:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-14 18:41:19 +00:00
|
|
|
~BOOST_FUNCTION_FUNCTION() { clear(); }
|
|
|
|
|
2005-08-25 16:27:28 +00:00
|
|
|
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
2004-07-11 03:09:35 +00:00
|
|
|
// MSVC 6.0 and prior require all definitions to be inline, but
|
|
|
|
// these definitions can become very costly.
|
2001-06-21 16:19:33 +00:00
|
|
|
result_type operator()(BOOST_FUNCTION_PARMS) const
|
|
|
|
{
|
2002-11-04 18:19:01 +00:00
|
|
|
if (this->empty())
|
|
|
|
boost::throw_exception(bad_function_call());
|
2001-06-21 16:19:33 +00:00
|
|
|
|
2007-09-13 17:38:58 +00:00
|
|
|
return reinterpret_cast<const vtable_type*>(vtable)->invoker
|
2005-12-30 02:31:51 +00:00
|
|
|
(this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
|
2001-06-21 16:19:33 +00:00
|
|
|
}
|
2004-07-11 03:09:35 +00:00
|
|
|
#else
|
|
|
|
result_type operator()(BOOST_FUNCTION_PARMS) const;
|
|
|
|
#endif
|
2001-06-21 16:19:33 +00:00
|
|
|
|
2001-07-14 19:34:14 +00:00
|
|
|
// The distinction between when to use BOOST_FUNCTION_FUNCTION and
|
|
|
|
// when to use self_type is obnoxious. MSVC cannot handle self_type as
|
|
|
|
// the return type of these assignment operators, but Borland C++ cannot
|
2002-09-24 19:52:56 +00:00
|
|
|
// handle BOOST_FUNCTION_FUNCTION as the type of the temporary to
|
2001-07-14 19:34:14 +00:00
|
|
|
// construct.
|
2001-06-29 19:33:29 +00:00
|
|
|
template<typename Functor>
|
2003-12-04 22:31:09 +00:00
|
|
|
#ifndef BOOST_NO_SFINAE
|
|
|
|
typename enable_if_c<
|
2005-08-24 14:12:03 +00:00
|
|
|
(boost::type_traits::ice_not<
|
2003-09-10 04:16:17 +00:00
|
|
|
(is_integral<Functor>::value)>::value),
|
2002-11-09 16:02:47 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION&>::type
|
|
|
|
#else
|
2002-09-24 19:52:56 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION&
|
2002-11-09 16:02:47 +00:00
|
|
|
#endif
|
2001-12-24 17:10:47 +00:00
|
|
|
operator=(Functor BOOST_FUNCTION_TARGET_FIX(const &) f)
|
2001-06-21 16:19:33 +00:00
|
|
|
{
|
2006-01-10 23:52:35 +00:00
|
|
|
this->clear();
|
2007-08-29 19:06:11 +00:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2006-01-10 23:52:35 +00:00
|
|
|
try {
|
|
|
|
this->assign_to(f);
|
|
|
|
} catch (...) {
|
|
|
|
vtable = 0;
|
|
|
|
throw;
|
|
|
|
}
|
2007-08-29 19:06:11 +00:00
|
|
|
#else
|
|
|
|
this->assign_to(f);
|
|
|
|
#endif
|
2001-06-29 19:33:29 +00:00
|
|
|
return *this;
|
2001-06-21 16:19:33 +00:00
|
|
|
}
|
|
|
|
|
2003-12-04 22:31:09 +00:00
|
|
|
#ifndef BOOST_NO_SFINAE
|
2002-11-09 16:02:47 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION& operator=(clear_type*)
|
|
|
|
{
|
|
|
|
this->clear();
|
|
|
|
return *this;
|
|
|
|
}
|
2002-12-15 14:51:16 +00:00
|
|
|
#else
|
2002-12-15 14:54:32 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION& operator=(int zero)
|
2002-12-15 14:51:16 +00:00
|
|
|
{
|
2002-12-15 14:54:32 +00:00
|
|
|
BOOST_ASSERT(zero == 0);
|
2002-12-15 14:51:16 +00:00
|
|
|
this->clear();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-09 16:02:47 +00:00
|
|
|
|
2001-06-21 16:19:33 +00:00
|
|
|
// Assignment from another BOOST_FUNCTION_FUNCTION
|
|
|
|
BOOST_FUNCTION_FUNCTION& operator=(const BOOST_FUNCTION_FUNCTION& f)
|
|
|
|
{
|
2001-07-14 18:41:19 +00:00
|
|
|
if (&f == this)
|
|
|
|
return *this;
|
|
|
|
|
2006-01-10 23:52:35 +00:00
|
|
|
this->clear();
|
2007-08-29 19:06:11 +00:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2006-01-10 23:52:35 +00:00
|
|
|
try {
|
|
|
|
this->assign_to_own(f);
|
|
|
|
} catch (...) {
|
|
|
|
vtable = 0;
|
|
|
|
throw;
|
|
|
|
}
|
2007-08-29 19:06:11 +00:00
|
|
|
#else
|
|
|
|
this->assign_to_own(f);
|
|
|
|
#endif
|
2001-06-21 16:19:33 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2001-07-14 18:41:19 +00:00
|
|
|
void swap(BOOST_FUNCTION_FUNCTION& other)
|
|
|
|
{
|
|
|
|
if (&other == this)
|
|
|
|
return;
|
|
|
|
|
2006-01-10 23:52:35 +00:00
|
|
|
BOOST_FUNCTION_FUNCTION tmp = *this;
|
|
|
|
*this = other;
|
|
|
|
other = tmp;
|
2001-07-14 18:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear out a target, if there is one
|
|
|
|
void clear()
|
|
|
|
{
|
2005-12-30 02:31:51 +00:00
|
|
|
if (vtable) {
|
2007-09-13 17:38:58 +00:00
|
|
|
reinterpret_cast<const vtable_type*>(vtable)->clear(this->functor);
|
2005-12-30 02:31:51 +00:00
|
|
|
vtable = 0;
|
2002-03-30 18:45:28 +00:00
|
|
|
}
|
2001-07-14 18:41:19 +00:00
|
|
|
}
|
|
|
|
|
2002-09-16 03:44:18 +00:00
|
|
|
#if (defined __SUNPRO_CC) && (__SUNPRO_CC <= 0x530) && !(defined BOOST_NO_COMPILER_CONFIG)
|
|
|
|
// Sun C++ 5.3 can't handle the safe_bool idiom, so don't use it
|
|
|
|
operator bool () const { return !this->empty(); }
|
|
|
|
#else
|
|
|
|
private:
|
|
|
|
struct dummy {
|
|
|
|
void nonnull() {};
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (dummy::*safe_bool)();
|
|
|
|
|
|
|
|
public:
|
2002-09-24 19:52:56 +00:00
|
|
|
operator safe_bool () const
|
2002-09-16 03:44:18 +00:00
|
|
|
{ return (this->empty())? 0 : &dummy::nonnull; }
|
|
|
|
|
|
|
|
bool operator!() const
|
|
|
|
{ return this->empty(); }
|
|
|
|
#endif
|
|
|
|
|
2001-07-14 18:41:19 +00:00
|
|
|
private:
|
|
|
|
void assign_to_own(const BOOST_FUNCTION_FUNCTION& f)
|
|
|
|
{
|
|
|
|
if (!f.empty()) {
|
2005-12-30 02:31:51 +00:00
|
|
|
this->vtable = f.vtable;
|
2006-01-10 23:52:35 +00:00
|
|
|
f.vtable->manager(f.functor, this->functor,
|
|
|
|
boost::detail::function::clone_functor_tag);
|
2002-09-24 19:52:56 +00:00
|
|
|
}
|
2001-07-14 18:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Functor>
|
2007-09-13 19:06:53 +00:00
|
|
|
void assign_to(const Functor& f)
|
2001-07-14 18:41:19 +00:00
|
|
|
{
|
2007-09-13 17:38:58 +00:00
|
|
|
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 =
|
2007-09-14 21:05:46 +00:00
|
|
|
{ { &manager_type::manage }, &invoker_type::invoke };
|
2007-09-13 17:38:58 +00:00
|
|
|
|
2007-09-14 21:05:46 +00:00
|
|
|
if (stored_vtable.assign_to(f, functor)) vtable = &stored_vtable.base;
|
2005-12-30 02:31:51 +00:00
|
|
|
else vtable = 0;
|
2002-09-24 19:52:56 +00:00
|
|
|
}
|
2001-06-21 16:19:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
2002-08-05 06:19:17 +00:00
|
|
|
typename Allocator>
|
2001-06-21 16:19:33 +00:00
|
|
|
inline void swap(BOOST_FUNCTION_FUNCTION<
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
|
|
|
Allocator
|
|
|
|
>& f1,
|
|
|
|
BOOST_FUNCTION_FUNCTION<
|
2002-09-24 19:52:56 +00:00
|
|
|
R BOOST_FUNCTION_COMMA
|
2001-06-21 16:19:33 +00:00
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS,
|
|
|
|
Allocator
|
|
|
|
>& f2)
|
|
|
|
{
|
|
|
|
f1.swap(f2);
|
2001-10-08 13:32:24 +00:00
|
|
|
}
|
2002-09-24 17:16:17 +00:00
|
|
|
|
2005-08-25 16:27:28 +00:00
|
|
|
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
2004-07-11 03:09:35 +00:00
|
|
|
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
|
|
|
|
typename Allocator>
|
|
|
|
typename BOOST_FUNCTION_FUNCTION<
|
2005-12-30 02:31:51 +00:00
|
|
|
R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS,
|
2004-07-11 03:09:35 +00:00
|
|
|
Allocator>::result_type
|
|
|
|
BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS,
|
|
|
|
|
|
|
|
Allocator>
|
|
|
|
::operator()(BOOST_FUNCTION_PARMS) const
|
|
|
|
{
|
2004-12-15 21:40:30 +00:00
|
|
|
if (this->empty())
|
|
|
|
boost::throw_exception(bad_function_call());
|
2005-12-30 02:31:51 +00:00
|
|
|
|
2007-09-13 17:38:58 +00:00
|
|
|
return reinterpret_cast<const vtable_type*>(vtable)->invoker
|
2005-12-30 02:31:51 +00:00
|
|
|
(this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
|
2004-12-15 21:40:30 +00:00
|
|
|
}
|
2004-07-11 03:09:35 +00:00
|
|
|
#endif
|
|
|
|
|
2004-01-20 18:02:02 +00:00
|
|
|
// Poison comparisons between boost::function objects of the same type.
|
|
|
|
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
|
|
|
typename Allocator>
|
|
|
|
void operator==(const BOOST_FUNCTION_FUNCTION<
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
|
|
|
Allocator>&,
|
|
|
|
const BOOST_FUNCTION_FUNCTION<
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
|
|
|
Allocator>&);
|
|
|
|
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
|
|
|
typename Allocator>
|
|
|
|
void operator!=(const BOOST_FUNCTION_FUNCTION<
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
|
|
|
Allocator>&,
|
|
|
|
const BOOST_FUNCTION_FUNCTION<
|
|
|
|
R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
|
|
|
Allocator>&);
|
|
|
|
|
2003-07-11 16:00:29 +00:00
|
|
|
#if !defined(BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX)
|
2002-09-24 17:16:17 +00:00
|
|
|
|
|
|
|
#if BOOST_FUNCTION_NUM_ARGS == 0
|
|
|
|
#define BOOST_FUNCTION_PARTIAL_SPEC R (void)
|
2002-09-24 19:52:56 +00:00
|
|
|
#else
|
2002-09-24 17:16:17 +00:00
|
|
|
#define BOOST_FUNCTION_PARTIAL_SPEC R (BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS,T))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<typename R BOOST_FUNCTION_COMMA
|
|
|
|
BOOST_FUNCTION_TEMPLATE_PARMS,
|
|
|
|
typename Allocator>
|
|
|
|
class function<BOOST_FUNCTION_PARTIAL_SPEC, Allocator>
|
2002-09-24 19:52:56 +00:00
|
|
|
: public BOOST_FUNCTION_FUNCTION<R, BOOST_FUNCTION_TEMPLATE_ARGS
|
2002-09-24 17:16:17 +00:00
|
|
|
BOOST_FUNCTION_COMMA Allocator>
|
|
|
|
{
|
2002-09-24 19:52:56 +00:00
|
|
|
typedef BOOST_FUNCTION_FUNCTION<R, BOOST_FUNCTION_TEMPLATE_ARGS
|
2002-09-24 17:16:17 +00:00
|
|
|
BOOST_FUNCTION_COMMA Allocator> base_type;
|
|
|
|
typedef function self_type;
|
|
|
|
|
2002-11-09 16:02:47 +00:00
|
|
|
struct clear_type {};
|
|
|
|
|
2002-09-24 17:16:17 +00:00
|
|
|
public:
|
|
|
|
typedef typename base_type::allocator_type allocator_type;
|
|
|
|
|
|
|
|
function() : base_type() {}
|
|
|
|
|
2002-09-24 19:52:56 +00:00
|
|
|
template<typename Functor>
|
2002-11-09 16:02:47 +00:00
|
|
|
function(Functor f
|
2003-12-04 22:31:09 +00:00
|
|
|
#ifndef BOOST_NO_SFINAE
|
|
|
|
,typename enable_if_c<
|
2005-08-24 14:12:03 +00:00
|
|
|
(boost::type_traits::ice_not<
|
2003-09-10 04:16:17 +00:00
|
|
|
(is_integral<Functor>::value)>::value),
|
2002-11-09 16:02:47 +00:00
|
|
|
int>::type = 0
|
|
|
|
#endif
|
|
|
|
) :
|
|
|
|
base_type(f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-12-04 22:31:09 +00:00
|
|
|
#ifndef BOOST_NO_SFINAE
|
2002-11-09 16:02:47 +00:00
|
|
|
function(clear_type*) : base_type() {}
|
|
|
|
#endif
|
2002-09-24 19:52:56 +00:00
|
|
|
|
2002-09-24 17:16:17 +00:00
|
|
|
function(const self_type& f) : base_type(static_cast<const base_type&>(f)){}
|
2002-09-24 19:52:56 +00:00
|
|
|
|
2002-11-04 18:19:01 +00:00
|
|
|
function(const base_type& f) : base_type(static_cast<const base_type&>(f)){}
|
|
|
|
|
|
|
|
self_type& operator=(const self_type& f)
|
2002-09-24 17:16:17 +00:00
|
|
|
{
|
|
|
|
self_type(f).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2002-11-04 18:19:01 +00:00
|
|
|
template<typename Functor>
|
2003-12-04 22:31:09 +00:00
|
|
|
#ifndef BOOST_NO_SFINAE
|
|
|
|
typename enable_if_c<
|
2005-08-24 14:12:03 +00:00
|
|
|
(boost::type_traits::ice_not<
|
2003-09-10 04:16:17 +00:00
|
|
|
(is_integral<Functor>::value)>::value),
|
2002-11-09 16:02:47 +00:00
|
|
|
self_type&>::type
|
|
|
|
#else
|
|
|
|
self_type&
|
|
|
|
#endif
|
|
|
|
operator=(Functor f)
|
2002-09-24 19:52:56 +00:00
|
|
|
{
|
2002-11-04 18:19:01 +00:00
|
|
|
self_type(f).swap(*this);
|
2002-09-24 17:16:17 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2002-10-08 02:32:38 +00:00
|
|
|
|
2003-12-04 22:31:09 +00:00
|
|
|
#ifndef BOOST_NO_SFINAE
|
2002-11-09 16:02:47 +00:00
|
|
|
self_type& operator=(clear_type*)
|
|
|
|
{
|
|
|
|
this->clear();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-11-04 18:19:01 +00:00
|
|
|
self_type& operator=(const base_type& f)
|
|
|
|
{
|
|
|
|
self_type(f).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2002-10-08 02:32:38 +00:00
|
|
|
};
|
|
|
|
|
2002-09-24 17:16:17 +00:00
|
|
|
#undef BOOST_FUNCTION_PARTIAL_SPEC
|
|
|
|
#endif // have partial specialization
|
|
|
|
|
|
|
|
} // end namespace boost
|
2001-06-29 19:33:29 +00:00
|
|
|
|
|
|
|
// Cleanup after ourselves...
|
2005-12-30 02:31:51 +00:00
|
|
|
#undef BOOST_FUNCTION_VTABLE
|
2007-09-13 17:38:58 +00:00
|
|
|
#undef BOOST_FUNCTION_GET_INVOKER
|
2001-10-06 20:28:27 +00:00
|
|
|
#undef BOOST_FUNCTION_DEFAULT_ALLOCATOR
|
2001-11-19 20:30:18 +00:00
|
|
|
#undef BOOST_FUNCTION_COMMA
|
|
|
|
#undef BOOST_FUNCTION_FUNCTION
|
|
|
|
#undef BOOST_FUNCTION_FUNCTION_INVOKER
|
|
|
|
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER
|
|
|
|
#undef BOOST_FUNCTION_FUNCTION_OBJ_INVOKER
|
|
|
|
#undef BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER
|
2006-01-10 23:52:35 +00:00
|
|
|
#undef BOOST_FUNCTION_FUNCTION_REF_INVOKER
|
|
|
|
#undef BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER
|
2007-09-13 17:38:58 +00:00
|
|
|
#undef BOOST_FUNCTION_MEMBER_INVOKER
|
|
|
|
#undef BOOST_FUNCTION_VOID_MEMBER_INVOKER
|
2001-11-19 20:30:18 +00:00
|
|
|
#undef BOOST_FUNCTION_GET_FUNCTION_INVOKER
|
|
|
|
#undef BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER
|
2006-01-10 23:52:35 +00:00
|
|
|
#undef BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER
|
2007-09-13 17:38:58 +00:00
|
|
|
#undef BOOST_FUNCTION_GET_MEMBER_INVOKER
|
2002-09-24 17:16:17 +00:00
|
|
|
#undef BOOST_FUNCTION_TEMPLATE_PARMS
|
|
|
|
#undef BOOST_FUNCTION_TEMPLATE_ARGS
|
|
|
|
#undef BOOST_FUNCTION_PARMS
|
|
|
|
#undef BOOST_FUNCTION_PARM
|
|
|
|
#undef BOOST_FUNCTION_ARGS
|
|
|
|
#undef BOOST_FUNCTION_ARG_TYPE
|
|
|
|
#undef BOOST_FUNCTION_ARG_TYPES
|
2004-12-15 21:40:30 +00:00
|
|
|
#undef BOOST_FUNCTION_VOID_RETURN_TYPE
|
|
|
|
#undef BOOST_FUNCTION_RETURN
|
2007-12-06 18:39:06 +00:00
|
|
|
|
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
# pragma warning( pop )
|
|
|
|
#endif
|