Boost.Function:

- Redesigned decision procedure for "is it a function pointer" vs.
	  "is it an object".
	- No longer requires copy constructions of function objects during
	  assignment or construction.
	- Added operator! to boost::function_base instead of relying on
	  safe_bool conversion.
	- BOOST_NO_DEPENDENT_BASE_LOOKUP is now unnecessary
	- BOOST_WEAK_CONVERSION_OPERATORS is now unnecessary
	- BOOST_WEAK_FUNCTION_TEMPLATE_ORDERING is now unnecessary


[SVN r10481]
This commit is contained in:
Douglas Gregor
2001-06-29 19:33:29 +00:00
parent 1678e1fde6
commit 73f380d5ac
14 changed files with 393 additions and 1090 deletions

View File

@ -456,56 +456,68 @@ namespace boost {
function() : base_type() {}
template<typename Functor>
function(Functor BOOST_MSVC_INCLUDE(const &) f) : base_type(f) {}
function(const Functor& f) : base_type(f) {}
#ifdef __BORLANDC__
template<typename Functor>
function(const Functor* fc) : base_type(fc) {}
#endif // __BORLANDC__
function(const function& f) : base_type(static_cast<const base_type&>(f)){}
template<typename Functor>
function& operator=(const Functor& f)
{
this->assign_to(f);
return *this;
}
#ifdef __BORLANDC__
template<typename Functor>
function& operator=(const Functor* fc)
{
Functor* f = const_cast<Functor*>(fc);
this->assign_to(f);
return *this;
}
#endif // __BORLANDC__
function& operator=(const base_type& f)
{
this->assign_to_own(f);
return *this;
}
function& operator=(const function& f)
{
if (this == &f)
this->assign_to_own(f);
return *this;
}
const base_type& bf = static_cast<const base_type&>(f);
base_type* self = this;
self->set(bf);
return *this;
template<typename Functor>
void set(const Functor& f)
{
this->assign_to(f);
}
#ifdef __BORLANDC__
template<typename Functor>
void set(const Functor* fc)
{
Functor* f = const_cast<Functor*>(fc);
this->assign_to(f);
}
#endif // __BORLANDC__
void set(const base_type& f)
{
this->assign_to_own(f);
}
void set(const function& f)
{
if (this == &f)
return;
const base_type& bf = static_cast<const base_type&>(f);
base_type* self = this;
self->set(bf);
this->assign_to_own(f);
}
void swap(function& other)
{
#ifndef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
std::swap(this->manager, other.manager);
std::swap(this->functor, other.functor);
std::swap(this->invoker, other.invoker);
#else
std::swap(this->impl, other.impl);
#endif // BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
}
#ifdef BOOST_NO_DEPENDENT_BASE_LOOKUP
template<typename Functor>
function& operator=(Functor BOOST_MSVC_INCLUDE(const &) f)
{
this->set(f);
return *this;
}
base_type& operator=(const base_type& f)
{
this->set(f);
return *this;
}
#endif // BOOST_NO_DEPENDENT_BASE_LOOKUP
};
template<typename R,

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS
#define BOOST_FUNCTION_ARGS
#define BOOST_FUNCTION_FUNCTION function0
#define BOOST_FUNCTION_BASE function0_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base0
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker0
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker0
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1
#define BOOST_FUNCTION_ARGS a1
#define BOOST_FUNCTION_FUNCTION function1
#define BOOST_FUNCTION_BASE function1_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base1
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker1
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker1
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9, T10 a10
#define BOOST_FUNCTION_ARGS a1, a2, a3, a4, a5, a6, a7, a8, a9, a10
#define BOOST_FUNCTION_FUNCTION function10
#define BOOST_FUNCTION_BASE function10_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base10
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker10
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker10
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2
#define BOOST_FUNCTION_ARGS a1, a2
#define BOOST_FUNCTION_FUNCTION function2
#define BOOST_FUNCTION_BASE function2_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base2
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker2
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker2
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2, T3 a3
#define BOOST_FUNCTION_ARGS a1, a2, a3
#define BOOST_FUNCTION_FUNCTION function3
#define BOOST_FUNCTION_BASE function3_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base3
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker3
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker3
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2, T3 a3, T4 a4
#define BOOST_FUNCTION_ARGS a1, a2, a3, a4
#define BOOST_FUNCTION_FUNCTION function4
#define BOOST_FUNCTION_BASE function4_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base4
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker4
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker4
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2, T3 a3, T4 a4, T5 a5
#define BOOST_FUNCTION_ARGS a1, a2, a3, a4, a5
#define BOOST_FUNCTION_FUNCTION function5
#define BOOST_FUNCTION_BASE function5_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base5
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker5
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker5
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6
#define BOOST_FUNCTION_ARGS a1, a2, a3, a4, a5, a6
#define BOOST_FUNCTION_FUNCTION function6
#define BOOST_FUNCTION_BASE function6_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base6
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker6
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker6
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7
#define BOOST_FUNCTION_ARGS a1, a2, a3, a4, a5, a6, a7
#define BOOST_FUNCTION_FUNCTION function7
#define BOOST_FUNCTION_BASE function7_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base7
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker7
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker7
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8
#define BOOST_FUNCTION_ARGS a1, a2, a3, a4, a5, a6, a7, a8
#define BOOST_FUNCTION_FUNCTION function8
#define BOOST_FUNCTION_BASE function8_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base8
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker8
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker8
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -27,6 +27,7 @@
#define BOOST_FUNCTION_PARMS T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9
#define BOOST_FUNCTION_ARGS a1, a2, a3, a4, a5, a6, a7, a8, a9
#define BOOST_FUNCTION_FUNCTION function9
#define BOOST_FUNCTION_BASE function9_base
#define BOOST_FUNCTION_INVOKER_BASE invoker_base9
#define BOOST_FUNCTION_FUNCTION_INVOKER function_invoker9
#define BOOST_FUNCTION_VOID_FUNCTION_INVOKER void_function_invoker9
@ -46,6 +47,7 @@
#undef BOOST_FUNCTION_PARMS
#undef BOOST_FUNCTION_ARGS
#undef BOOST_FUNCTION_FUNCTION
#undef BOOST_FUNCTION_BASE
#undef BOOST_FUNCTION_INVOKER_BASE
#undef BOOST_FUNCTION_FUNCTION_INVOKER
#undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER

View File

@ -22,13 +22,6 @@
#include <boost/config.hpp>
#include <boost/type_traits.hpp>
// Microsoft Visual C++ 6.0sp5 has lots of quirks
#ifdef BOOST_MSVC
# define BOOST_MSVC_INCLUDE(x) x
#else
# define BOOST_MSVC_INCLUDE(x)
#endif
namespace boost {
namespace detail {
namespace function {
@ -191,7 +184,6 @@ namespace boost {
type */
pointer_type victim = static_cast<pointer_type>(f);
// Destroy and deallocate the functor
allocator.destroy(victim);
allocator.deallocate(victim, 1);
@ -285,22 +277,19 @@ namespace boost {
detail::function::any_pointer functor;
#endif // BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
#ifndef BOOST_WEAK_CONVERSION_OPERATORS
private:
struct dummy {
void nonnull() {};
};
typedef void (dummy::*safe_bool)();
public:
operator safe_bool () const
{
return (this->empty())? 0 : &dummy::nonnull;
}
#else
public:
operator bool() const { return !this->empty(); }
#endif // BOOST_WEAK_CONVERSION_OPERATORS
{ return (this->empty())? 0 : &dummy::nonnull; }
safe_bool operator!() const
{ return (this->empty())? &dummy::nonnull : 0; }
};
/* Poison comparison between Boost.Function objects (because it is

File diff suppressed because it is too large Load Diff