function_base.hpp:

- Updated any_pointer and manager classes to deal with member function
    pointers directly, so no allocation is required when using them.
  - Removed include of boost/mem_fn.hpp

function_template.hpp:
  - Many macros that were in the functionN.hpp headers have been moved here and
    are now generated on-the-fly using BOOST_JOIN
  - Added invokers for pointers to member functions
  - Revised pointer to member function handling code to not perform any
    allocations/deallocations
  - Added guards so that multiple inclusion of function_template.hpp will only
    include its dependencies once.

functionN.hpp:
  - Headers regenerated


[SVN r11729]
This commit is contained in:
Douglas Gregor
2001-11-19 20:30:18 +00:00
parent d37d210685
commit b8e4cdab2f
13 changed files with 353 additions and 461 deletions

View File

@ -23,7 +23,6 @@
#include <typeinfo>
#include <boost/config.hpp>
#include <boost/type_traits.hpp>
#include <boost/mem_fn.hpp>
namespace boost {
namespace detail {
@ -80,13 +79,17 @@ namespace boost {
* so function requires a union of the two. */
union any_pointer
{
struct container {};
void* obj_ptr;
const void* const_obj_ptr;
void (*func_ptr)();
void (container::* mem_func_ptr)();
explicit any_pointer(void* p) : obj_ptr(p) {}
explicit any_pointer(const void* p) : const_obj_ptr(p) {}
explicit any_pointer(void (*p)()) : func_ptr(p) {}
explicit any_pointer(void (container::*p)()) : mem_func_ptr(p) {}
};
/**
@ -116,8 +119,7 @@ namespace boost {
// The operation type to perform on the given functor/function pointer
enum functor_manager_operation_type {
clone_functor,
destroy_functor,
retrieve_type_info
destroy_functor
};
// Tags used to decide between different types of functions
@ -147,13 +149,6 @@ namespace boost {
{
private:
typedef Functor functor_type;
# ifndef BOOST_NO_STD_ALLOCATOR
typedef typename Allocator::template rebind<functor_type>::other
allocator_type;
typedef typename allocator_type::pointer pointer_type;
# else
typedef functor_type* pointer_type;
# endif // BOOST_NO_STD_ALLOCATOR
// For function pointers, the manager is trivial
static inline any_pointer
@ -162,10 +157,22 @@ namespace boost {
{
if (op == clone_functor)
return function_ptr;
else if (op == destroy_functor)
return any_pointer(static_cast<void (*)()>(0));
else
return any_pointer(&typeid(Functor));
return any_pointer(static_cast<void (*)()>(0));
}
// For member function pointers, the manager is trivial
static inline any_pointer
manager(any_pointer member_ptr, functor_manager_operation_type op,
member_ptr_tag)
{
if (op == clone_functor)
return member_ptr;
else {
typedef void (any_pointer::container::* stored_mem_func_type)();
stored_mem_func_type p = 0;
return any_pointer(p);
}
}
// For function object pointers, we clone the pointer to each
@ -175,6 +182,14 @@ namespace boost {
functor_manager_operation_type op,
function_obj_tag)
{
#ifndef BOOST_NO_STD_ALLOCATOR
typedef typename Allocator::template rebind<functor_type>::other
allocator_type;
typedef typename allocator_type::pointer pointer_type;
#else
typedef functor_type* pointer_type;
#endif // BOOST_NO_STD_ALLOCATOR
# ifndef BOOST_NO_STD_ALLOCATOR
allocator_type allocator;
# endif // BOOST_NO_STD_ALLOCATOR
@ -195,7 +210,7 @@ namespace boost {
# endif // BOOST_NO_STD_ALLOCATOR
return any_pointer(static_cast<void*>(new_f));
}
else if (op == destroy_functor) {
else {
/* Cast from the void pointer to the functor pointer type */
functor_type* f =
reinterpret_cast<functor_type*>(function_obj_ptr.obj_ptr);
@ -214,9 +229,6 @@ namespace boost {
return any_pointer(static_cast<void*>(0));
}
else {
return any_pointer(&typeid(Functor));
}
}
public:
/* Dispatch to an appropriate manager based on whether we have a
@ -224,10 +236,7 @@ namespace boost {
static any_pointer
manage(any_pointer functor_ptr, functor_manager_operation_type op)
{
typedef typename IF<(is_pointer<functor_type>::value),
function_ptr_tag,
function_obj_tag>::type tag_type;
typedef typename get_function_tag<functor_type>::type tag_type;
return manager(functor_ptr, op, tag_type());
}
};