forked from boostorg/function
Changed implementation to avoid calculating the size of the raw data buffer manually. Trim trailing spaces.
This commit is contained in:
@@ -97,7 +97,7 @@ namespace boost {
|
||||
static R invoke(function_buffer& function_ptr BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
{
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.members.func_ptr);
|
||||
return f(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
};
|
||||
@@ -114,7 +114,7 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.members.func_ptr);
|
||||
BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
};
|
||||
@@ -134,7 +134,7 @@ namespace boost {
|
||||
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);
|
||||
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
|
||||
return (*f)(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
};
|
||||
@@ -155,7 +155,7 @@ namespace boost {
|
||||
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);
|
||||
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
|
||||
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
};
|
||||
@@ -171,8 +171,8 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionObj* f =
|
||||
reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
||||
FunctionObj* f =
|
||||
reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
|
||||
return (*f)(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
};
|
||||
@@ -189,8 +189,8 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionObj* f =
|
||||
reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
||||
FunctionObj* f =
|
||||
reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
|
||||
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
};
|
||||
@@ -208,7 +208,7 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
MemberPtr* f =
|
||||
MemberPtr* f =
|
||||
reinterpret_cast<MemberPtr*>(function_obj_ptr.data);
|
||||
return boost::mem_fn(*f)(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
@@ -226,7 +226,7 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
MemberPtr* f =
|
||||
MemberPtr* f =
|
||||
reinterpret_cast<MemberPtr*>(function_obj_ptr.data);
|
||||
BOOST_FUNCTION_RETURN(boost::mem_fn(*f)(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
@@ -322,7 +322,7 @@ namespace boost {
|
||||
|
||||
/* Given the tag returned by get_function_tag, retrieve the
|
||||
actual invoker that will be used for the given function
|
||||
object.
|
||||
object.
|
||||
|
||||
Each specialization contains an "apply" nested class template
|
||||
that accepts the function object, return type, function
|
||||
@@ -513,21 +513,21 @@ namespace boost {
|
||||
private:
|
||||
// Function pointers
|
||||
template<typename FunctionPtr>
|
||||
bool
|
||||
bool
|
||||
assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag) const
|
||||
{
|
||||
this->clear(functor);
|
||||
if (f) {
|
||||
// should be a reinterpret cast, but some compilers insist
|
||||
// on giving cv-qualifiers to free functions
|
||||
functor.func_ptr = reinterpret_cast<void (*)()>(f);
|
||||
functor.members.func_ptr = reinterpret_cast<void (*)()>(f);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
template<typename FunctionPtr,typename Allocator>
|
||||
bool
|
||||
bool
|
||||
assign_to_a(FunctionPtr f, function_buffer& functor, Allocator, function_ptr_tag) const
|
||||
{
|
||||
return assign_to(f,functor,function_ptr_tag());
|
||||
@@ -566,13 +566,13 @@ namespace boost {
|
||||
// Function objects
|
||||
// Assign to a function object using the small object optimization
|
||||
template<typename FunctionObj>
|
||||
void
|
||||
void
|
||||
assign_functor(FunctionObj f, function_buffer& functor, mpl::true_) const
|
||||
{
|
||||
new (reinterpret_cast<void*>(functor.data)) FunctionObj(f);
|
||||
}
|
||||
template<typename FunctionObj,typename Allocator>
|
||||
void
|
||||
void
|
||||
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, mpl::true_) const
|
||||
{
|
||||
assign_functor(f,functor,mpl::true_());
|
||||
@@ -580,13 +580,13 @@ namespace boost {
|
||||
|
||||
// Assign to a function object allocated on the heap.
|
||||
template<typename FunctionObj>
|
||||
void
|
||||
void
|
||||
assign_functor(FunctionObj f, function_buffer& functor, mpl::false_) const
|
||||
{
|
||||
functor.obj_ptr = new FunctionObj(f);
|
||||
functor.members.obj_ptr = new FunctionObj(f);
|
||||
}
|
||||
template<typename FunctionObj,typename Allocator>
|
||||
void
|
||||
void
|
||||
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, mpl::false_) const
|
||||
{
|
||||
typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type;
|
||||
@@ -597,15 +597,15 @@ namespace boost {
|
||||
wrapper_allocator_pointer_type copy = wrapper_allocator.allocate(1);
|
||||
wrapper_allocator.construct(copy, functor_wrapper_type(f,a));
|
||||
functor_wrapper_type* new_f = static_cast<functor_wrapper_type*>(copy);
|
||||
functor.obj_ptr = new_f;
|
||||
functor.members.obj_ptr = new_f;
|
||||
}
|
||||
|
||||
template<typename FunctionObj>
|
||||
bool
|
||||
bool
|
||||
assign_to(FunctionObj f, function_buffer& functor, function_obj_tag) const
|
||||
{
|
||||
if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
|
||||
assign_functor(f, functor,
|
||||
assign_functor(f, functor,
|
||||
mpl::bool_<(function_allows_small_object_optimization<FunctionObj>::value)>());
|
||||
return true;
|
||||
} else {
|
||||
@@ -613,7 +613,7 @@ namespace boost {
|
||||
}
|
||||
}
|
||||
template<typename FunctionObj,typename Allocator>
|
||||
bool
|
||||
bool
|
||||
assign_to_a(FunctionObj f, function_buffer& functor, Allocator a, function_obj_tag) const
|
||||
{
|
||||
if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
|
||||
@@ -627,18 +627,18 @@ namespace boost {
|
||||
|
||||
// Reference to a function object
|
||||
template<typename FunctionObj>
|
||||
bool
|
||||
assign_to(const reference_wrapper<FunctionObj>& f,
|
||||
bool
|
||||
assign_to(const reference_wrapper<FunctionObj>& f,
|
||||
function_buffer& functor, function_obj_ref_tag) const
|
||||
{
|
||||
functor.obj_ref.obj_ptr = (void *)(f.get_pointer());
|
||||
functor.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
|
||||
functor.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
|
||||
functor.members.obj_ref.obj_ptr = (void *)(f.get_pointer());
|
||||
functor.members.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
|
||||
functor.members.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
|
||||
return true;
|
||||
}
|
||||
template<typename FunctionObj,typename Allocator>
|
||||
bool
|
||||
assign_to_a(const reference_wrapper<FunctionObj>& f,
|
||||
bool
|
||||
assign_to_a(const reference_wrapper<FunctionObj>& f,
|
||||
function_buffer& functor, Allocator, function_obj_ref_tag) const
|
||||
{
|
||||
return assign_to(f,functor,function_obj_ref_tag());
|
||||
@@ -921,7 +921,7 @@ namespace boost {
|
||||
typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
|
||||
typedef boost::detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||
typedef typename get_invoker::
|
||||
template apply<Functor, R BOOST_FUNCTION_COMMA
|
||||
template apply<Functor, R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS>
|
||||
handler_type;
|
||||
|
||||
@@ -932,7 +932,7 @@ namespace boost {
|
||||
// static initialization. Otherwise, we will have a race
|
||||
// condition here in multi-threaded code. See
|
||||
// http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
|
||||
static const vtable_type stored_vtable =
|
||||
static const vtable_type stored_vtable =
|
||||
{ { &manager_type::manage }, &invoker_type::invoke };
|
||||
|
||||
if (stored_vtable.assign_to(f, functor)) {
|
||||
@@ -943,7 +943,7 @@ namespace boost {
|
||||
boost::detail::function::function_allows_small_object_optimization<Functor>::value)
|
||||
value |= static_cast<std::size_t>(0x01);
|
||||
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
|
||||
} else
|
||||
} else
|
||||
vtable = 0;
|
||||
}
|
||||
|
||||
@@ -955,7 +955,7 @@ namespace boost {
|
||||
typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
|
||||
typedef boost::detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||
typedef typename get_invoker::
|
||||
template apply_a<Functor, R BOOST_FUNCTION_COMMA
|
||||
template apply_a<Functor, R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS,
|
||||
Allocator>
|
||||
handler_type;
|
||||
@@ -970,7 +970,7 @@ namespace boost {
|
||||
static const vtable_type stored_vtable =
|
||||
{ { &manager_type::manage }, &invoker_type::invoke };
|
||||
|
||||
if (stored_vtable.assign_to_a(f, functor, a)) {
|
||||
if (stored_vtable.assign_to_a(f, functor, a)) {
|
||||
std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
|
||||
// coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
|
||||
if (boost::has_trivial_copy_constructor<Functor>::value &&
|
||||
@@ -978,14 +978,14 @@ namespace boost {
|
||||
boost::detail::function::function_allows_small_object_optimization<Functor>::value)
|
||||
value |= static_cast<std::size_t>(0x01);
|
||||
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
|
||||
} else
|
||||
} else
|
||||
vtable = 0;
|
||||
}
|
||||
|
||||
// Moves the value from the specified argument to *this. If the argument
|
||||
// has its function object allocated on the heap, move_assign will pass
|
||||
// its buffer to *this, and set the argument's buffer pointer to NULL.
|
||||
void move_assign(BOOST_FUNCTION_FUNCTION& f)
|
||||
// Moves the value from the specified argument to *this. If the argument
|
||||
// has its function object allocated on the heap, move_assign will pass
|
||||
// its buffer to *this, and set the argument's buffer pointer to NULL.
|
||||
void move_assign(BOOST_FUNCTION_FUNCTION& f)
|
||||
{
|
||||
if (&f == this)
|
||||
return;
|
||||
@@ -1139,7 +1139,7 @@ public:
|
||||
self_type(f).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
self_type& operator=(base_type&& f)
|
||||
{
|
||||
|
Reference in New Issue
Block a user