Taking function objects by value instead of as references-to-const. This does not work on MSVC6.5, so the BOOST_MSVC_ONLY macro was added to make them references-to-const for only that compiler.

- Borland C++ no longer requires hacks to make function pointers work
- On any compiler other than MSVC, free functions can be assigned to Boost.Function objects without the explicit '&'


[SVN r11943]
This commit is contained in:
Douglas Gregor
2001-12-05 22:35:32 +00:00
parent 8cbd121969
commit 083767f67a
5 changed files with 26 additions and 65 deletions

View File

@ -456,56 +456,35 @@ namespace boost {
function() : base_type() {}
template<typename Functor>
function(const Functor& f) : base_type(f) {}
function(Functor BOOST_MSVC_ONLY(const &) f) : base_type(f) {}
#ifdef __BORLANDC__
template<typename Functor> function(Functor* f) : base_type(f) {}
#endif // __BORLANDC__
function(const self_type& f) : base_type(static_cast<const base_type&>(f)){}
template<typename Functor>
function& operator=(const Functor& f)
self_type& operator=(Functor BOOST_MSVC_ONLY(const &) f)
{
self_type(f).swap(*this);
return *this;
}
#ifdef __BORLANDC__
template<typename Functor>
self_type& operator=(Functor* f)
{
self_type(f).swap(*this);
return *this;
}
#endif // __BORLANDC__
self_type& operator=(const base_type& f)
{
self_type(f).swap(*this);
return *this;
}
self_type& operator=(const self_type& f)
self_type& operator=(const self_type& f)
{
self_type(f).swap(*this);
return *this;
}
template<typename Functor>
void set(const Functor& f)
void set(Functor BOOST_MSVC_ONLY(const &) f)
{
self_type(f).swap(*this);
}
#ifdef __BORLANDC__
template<typename Functor>
void set(Functor* f)
{
self_type(f).swap(*this);
}
#endif // __BORLANDC__
void set(const base_type& f)
{
self_type(f).swap(*this);

View File

@ -25,6 +25,12 @@
#include <boost/type_traits.hpp>
#include <boost/ref.hpp>
#ifdef BOOST_MSVC
# define BOOST_MSVC_ONLY(x) x
#else
# define BOOST_MSVC_ONLY(x)
#endif // not MSVC
namespace boost {
namespace detail {
namespace function {

View File

@ -203,23 +203,14 @@ namespace boost {
// MSVC chokes if the following two constructors are collapsed into
// one with a default parameter.
template<typename Functor>
BOOST_FUNCTION_FUNCTION(const Functor& f) :
BOOST_FUNCTION_FUNCTION(Functor BOOST_MSVC_ONLY(const &) f) :
function_base(), Mixin(), invoker(0)
{
this->assign_to(f);
}
#ifdef __BORLANDC__
template<typename Functor>
BOOST_FUNCTION_FUNCTION(Functor* f) :
function_base(), Mixin(), invoker(0)
{
this->assign_to(f);
}
#endif // __BORLANDC__
template<typename Functor>
BOOST_FUNCTION_FUNCTION(const Functor& f, const Mixin& m) :
BOOST_FUNCTION_FUNCTION(Functor f, const Mixin& m) :
function_base(), Mixin(m), invoker(0)
{
this->assign_to(f);
@ -253,35 +244,18 @@ namespace boost {
// handle BOOST_FUNCTION_FUNCTION as the type of the temporary to
// construct.
template<typename Functor>
BOOST_FUNCTION_FUNCTION& operator=(const Functor& f)
BOOST_FUNCTION_FUNCTION& operator=(Functor f)
{
self_type(f, static_cast<const Mixin&>(*this)).swap(*this);
return *this;
}
#ifdef __BORLANDC__
template<typename Functor>
BOOST_FUNCTION_FUNCTION& operator=(Functor* f)
{
self_type(f, static_cast<const Mixin&>(*this)).swap(*this);
return *this;
}
#endif // __BORLANDC__
template<typename Functor>
void set(const Functor& f)
void set(Functor f)
{
self_type(f, static_cast<const Mixin&>(*this)).swap(*this);
}
#ifdef __BORLANDC__
template<typename Functor>
void set(Functor* f)
{
self_type(f, static_cast<const Mixin&>(*this)).swap(*this);
}
#endif // __BORLANDC__
// Assignment from another BOOST_FUNCTION_FUNCTION
BOOST_FUNCTION_FUNCTION& operator=(const BOOST_FUNCTION_FUNCTION& f)
{
@ -333,7 +307,7 @@ namespace boost {
}
template<typename Functor>
void assign_to(const Functor& f)
void assign_to(Functor f)
{
typedef typename detail::function::get_function_tag<Functor>::type tag;
this->assign_to(f, tag());
@ -356,7 +330,9 @@ namespace boost {
manager = &detail::function::functor_manager<FunctionPtr,
Allocator>::manage;
functor = manager(detail::function::any_pointer(
reinterpret_cast<void (*)()>(f)
// should be a reinterpret cast, but some compilers
// insist on giving cv-qualifiers to free functions
(void (*)())(f)
),
detail::function::clone_functor_tag);
}
@ -371,7 +347,7 @@ namespace boost {
#endif // BOOST_FUNCTION_NUM_ARGS > 0
template<typename FunctionObj>
void assign_to(const FunctionObj& f, detail::function::function_obj_tag)
void assign_to(FunctionObj f, detail::function::function_obj_tag)
{
if (!detail::function::has_empty_target(&f)) {
typedef