mirror of
https://github.com/boostorg/function.git
synced 2025-07-21 16:42:07 +02:00
function_base.hpp:
- Don't try to implicitly convert a function pointer to a data pointer stateless_test.cpp: - Don't use the deprecated syntax [SVN r15499]
This commit is contained in:
@ -10,7 +10,7 @@
|
|||||||
//
|
//
|
||||||
// This software is provided "as is" without express or implied warranty,
|
// This software is provided "as is" without express or implied warranty,
|
||||||
// and with no claim as to its suitability for any purpose.
|
// and with no claim as to its suitability for any purpose.
|
||||||
|
|
||||||
// For more information, see http://www.boost.org
|
// For more information, see http://www.boost.org
|
||||||
|
|
||||||
#ifndef BOOST_FUNCTION_BASE_HEADER
|
#ifndef BOOST_FUNCTION_BASE_HEADER
|
||||||
@ -39,7 +39,7 @@ template<typename Signature, typename Allocator = std::allocator<void> >
|
|||||||
class function;
|
class function;
|
||||||
|
|
||||||
template<typename Signature, typename Allocator>
|
template<typename Signature, typename Allocator>
|
||||||
inline void swap(function<Signature, Allocator>& f1,
|
inline void swap(function<Signature, Allocator>& f1,
|
||||||
function<Signature, Allocator>& f2)
|
function<Signature, Allocator>& f2)
|
||||||
{
|
{
|
||||||
f1.swap(f2);
|
f1.swap(f2);
|
||||||
@ -53,38 +53,38 @@ namespace boost {
|
|||||||
namespace function {
|
namespace function {
|
||||||
/**
|
/**
|
||||||
* A union of a function pointer and a void pointer. This is necessary
|
* A union of a function pointer and a void pointer. This is necessary
|
||||||
* because 5.2.10/6 allows reinterpret_cast<> to safely cast between
|
* because 5.2.10/6 allows reinterpret_cast<> to safely cast between
|
||||||
* function pointer types and 5.2.9/10 allows static_cast<> to safely
|
* function pointer types and 5.2.9/10 allows static_cast<> to safely
|
||||||
* cast between a void pointer and an object pointer. But it is not legal
|
* cast between a void pointer and an object pointer. But it is not legal
|
||||||
* to cast between a function pointer and a void* (in either direction),
|
* to cast between a function pointer and a void* (in either direction),
|
||||||
* so function requires a union of the two. */
|
* so function requires a union of the two. */
|
||||||
union any_pointer
|
union any_pointer
|
||||||
{
|
{
|
||||||
void* obj_ptr;
|
void* obj_ptr;
|
||||||
const void* const_obj_ptr;
|
const void* const_obj_ptr;
|
||||||
void (*func_ptr)();
|
void (*func_ptr)();
|
||||||
char data[1];
|
char data[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
any_pointer make_any_pointer(void* o)
|
any_pointer make_any_pointer(void* o)
|
||||||
{
|
{
|
||||||
any_pointer p;
|
any_pointer p;
|
||||||
p.obj_ptr = o;
|
p.obj_ptr = o;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
any_pointer make_any_pointer(const void* o)
|
any_pointer make_any_pointer(const void* o)
|
||||||
{
|
{
|
||||||
any_pointer p;
|
any_pointer p;
|
||||||
p.const_obj_ptr = o;
|
p.const_obj_ptr = o;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
any_pointer make_any_pointer(void (*f)())
|
any_pointer make_any_pointer(void (*f)())
|
||||||
{
|
{
|
||||||
any_pointer p;
|
any_pointer p;
|
||||||
p.obj_ptr = f;
|
p.func_ptr = f;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +93,7 @@ namespace boost {
|
|||||||
* anything. This helps compilers without partial specialization to
|
* anything. This helps compilers without partial specialization to
|
||||||
* handle Boost.Function objects returning void.
|
* handle Boost.Function objects returning void.
|
||||||
*/
|
*/
|
||||||
struct unusable
|
struct unusable
|
||||||
{
|
{
|
||||||
unusable() {}
|
unusable() {}
|
||||||
template<typename T> unusable(const T&) {}
|
template<typename T> unusable(const T&) {}
|
||||||
@ -101,19 +101,19 @@ namespace boost {
|
|||||||
|
|
||||||
/* Determine the return type. This supports compilers that do not support
|
/* Determine the return type. This supports compilers that do not support
|
||||||
* void returns or partial specialization by silently changing the return
|
* void returns or partial specialization by silently changing the return
|
||||||
* type to "unusable".
|
* type to "unusable".
|
||||||
*/
|
*/
|
||||||
template<typename T> struct function_return_type { typedef T type; };
|
template<typename T> struct function_return_type { typedef T type; };
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct function_return_type<void>
|
struct function_return_type<void>
|
||||||
{
|
{
|
||||||
typedef unusable type;
|
typedef unusable type;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The operation type to perform on the given functor/function pointer
|
// The operation type to perform on the given functor/function pointer
|
||||||
enum functor_manager_operation_type {
|
enum functor_manager_operation_type {
|
||||||
clone_functor_tag,
|
clone_functor_tag,
|
||||||
destroy_functor_tag
|
destroy_functor_tag
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ namespace boost {
|
|||||||
|
|
||||||
// The trivial manager does nothing but return the same pointer (if we
|
// The trivial manager does nothing but return the same pointer (if we
|
||||||
// are cloning) or return the null pointer (if we are deleting).
|
// are cloning) or return the null pointer (if we are deleting).
|
||||||
inline any_pointer trivial_manager(any_pointer f,
|
inline any_pointer trivial_manager(any_pointer f,
|
||||||
functor_manager_operation_type op)
|
functor_manager_operation_type op)
|
||||||
{
|
{
|
||||||
if (op == clone_functor_tag)
|
if (op == clone_functor_tag)
|
||||||
@ -158,7 +158,7 @@ namespace boost {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The functor_manager class contains a static function "manage" which
|
* The functor_manager class contains a static function "manage" which
|
||||||
* can clone or destroy the given function/function object pointer.
|
* can clone or destroy the given function/function object pointer.
|
||||||
*/
|
*/
|
||||||
template<typename Functor, typename Allocator>
|
template<typename Functor, typename Allocator>
|
||||||
struct functor_manager
|
struct functor_manager
|
||||||
@ -168,7 +168,7 @@ namespace boost {
|
|||||||
|
|
||||||
// For function pointers, the manager is trivial
|
// For function pointers, the manager is trivial
|
||||||
static inline any_pointer
|
static inline any_pointer
|
||||||
manager(any_pointer function_ptr,
|
manager(any_pointer function_ptr,
|
||||||
functor_manager_operation_type op,
|
functor_manager_operation_type op,
|
||||||
function_ptr_tag)
|
function_ptr_tag)
|
||||||
{
|
{
|
||||||
@ -178,15 +178,15 @@ namespace boost {
|
|||||||
return make_any_pointer(static_cast<void (*)()>(0));
|
return make_any_pointer(static_cast<void (*)()>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// For function object pointers, we clone the pointer to each
|
// For function object pointers, we clone the pointer to each
|
||||||
// function has its own version.
|
// function has its own version.
|
||||||
static inline any_pointer
|
static inline any_pointer
|
||||||
manager(any_pointer function_obj_ptr,
|
manager(any_pointer function_obj_ptr,
|
||||||
functor_manager_operation_type op,
|
functor_manager_operation_type op,
|
||||||
function_obj_tag)
|
function_obj_tag)
|
||||||
{
|
{
|
||||||
#ifndef BOOST_NO_STD_ALLOCATOR
|
#ifndef BOOST_NO_STD_ALLOCATOR
|
||||||
typedef typename Allocator::template rebind<functor_type>::other
|
typedef typename Allocator::template rebind<functor_type>::other
|
||||||
allocator_type;
|
allocator_type;
|
||||||
typedef typename allocator_type::pointer pointer_type;
|
typedef typename allocator_type::pointer pointer_type;
|
||||||
#else
|
#else
|
||||||
@ -198,7 +198,7 @@ namespace boost {
|
|||||||
# endif // BOOST_NO_STD_ALLOCATOR
|
# endif // BOOST_NO_STD_ALLOCATOR
|
||||||
|
|
||||||
if (op == clone_functor_tag) {
|
if (op == clone_functor_tag) {
|
||||||
functor_type* f =
|
functor_type* f =
|
||||||
static_cast<functor_type*>(function_obj_ptr.obj_ptr);
|
static_cast<functor_type*>(function_obj_ptr.obj_ptr);
|
||||||
|
|
||||||
// Clone the functor
|
// Clone the functor
|
||||||
@ -215,7 +215,7 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Cast from the void pointer to the functor pointer type */
|
/* Cast from the void pointer to the functor pointer type */
|
||||||
functor_type* f =
|
functor_type* f =
|
||||||
reinterpret_cast<functor_type*>(function_obj_ptr.obj_ptr);
|
reinterpret_cast<functor_type*>(function_obj_ptr.obj_ptr);
|
||||||
|
|
||||||
# ifndef BOOST_NO_STD_ALLOCATOR
|
# ifndef BOOST_NO_STD_ALLOCATOR
|
||||||
@ -250,27 +250,27 @@ namespace boost {
|
|||||||
* The function_base class contains the basic elements needed for the
|
* The function_base class contains the basic elements needed for the
|
||||||
* function1, function2, function3, etc. classes. It is common to all
|
* function1, function2, function3, etc. classes. It is common to all
|
||||||
* functions (and as such can be used to tell if we have one of the
|
* functions (and as such can be used to tell if we have one of the
|
||||||
* functionN objects).
|
* functionN objects).
|
||||||
*/
|
*/
|
||||||
class function_base
|
class function_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
function_base() : manager(0)
|
function_base() : manager(0)
|
||||||
{
|
{
|
||||||
functor.obj_ptr = 0;
|
functor.obj_ptr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is this function empty?
|
// Is this function empty?
|
||||||
bool empty() const { return !manager; }
|
bool empty() const { return !manager; }
|
||||||
|
|
||||||
public: // should be protected, but GCC 2.95.3 will fail to allow access
|
public: // should be protected, but GCC 2.95.3 will fail to allow access
|
||||||
detail::function::any_pointer (*manager)(
|
detail::function::any_pointer (*manager)(
|
||||||
detail::function::any_pointer,
|
detail::function::any_pointer,
|
||||||
detail::function::functor_manager_operation_type);
|
detail::function::functor_manager_operation_type);
|
||||||
detail::function::any_pointer functor;
|
detail::function::any_pointer functor;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Poison comparison between Boost.Function objects (because it is
|
/* Poison comparison between Boost.Function objects (because it is
|
||||||
* meaningless). The comparisons would otherwise be allowed because of the
|
* meaningless). The comparisons would otherwise be allowed because of the
|
||||||
* conversion required to allow syntax such as:
|
* conversion required to allow syntax such as:
|
||||||
* boost::function<int, int> f;
|
* boost::function<int, int> f;
|
||||||
|
@ -40,7 +40,7 @@ namespace boost {
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
boost::function<int, int, int> f;
|
boost::function2<int, int, int> f;
|
||||||
f = stateless_integer_add();
|
f = stateless_integer_add();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user