mirror of
https://github.com/boostorg/function.git
synced 2025-07-23 09:27:14 +02:00
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:
@ -456,30 +456,17 @@ namespace boost {
|
||||
function() : base_type() {}
|
||||
|
||||
template<typename Functor>
|
||||
function(const Functor& f) : base_type(f) {}
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
template<typename Functor> function(Functor* f) : base_type(f) {}
|
||||
#endif // __BORLANDC__
|
||||
function(Functor BOOST_MSVC_ONLY(const &) f) : base_type(f) {}
|
||||
|
||||
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);
|
||||
@ -493,19 +480,11 @@ namespace boost {
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -102,7 +102,7 @@ test_zero_args()
|
||||
BOOST_TEST(v1.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v1 = &write_five;
|
||||
v1 = write_five;
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
@ -129,7 +129,7 @@ test_zero_args()
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v1 = &write_three;
|
||||
v1 = write_three;
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
|
@ -102,7 +102,7 @@ test_zero_args()
|
||||
BOOST_TEST(v1.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v1 = &write_five;
|
||||
v1 = BOOST_MSVC_ONLY(&) write_five;
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
@ -111,7 +111,7 @@ test_zero_args()
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v1 = &write_three;
|
||||
v1 = BOOST_MSVC_ONLY(&) write_three;
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
@ -163,7 +163,7 @@ test_zero_args()
|
||||
BOOST_TEST(v2.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v2.set(&write_five);
|
||||
v2.set(BOOST_MSVC_ONLY(&) write_five);
|
||||
BOOST_TEST(v2);
|
||||
|
||||
// Invocation
|
||||
@ -172,7 +172,7 @@ test_zero_args()
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v2 = &write_three;
|
||||
v2 = BOOST_MSVC_ONLY(&) write_three;
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
@ -227,7 +227,7 @@ test_zero_args()
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assign to a function from a function with a function
|
||||
v2 = &write_five;
|
||||
v2 = BOOST_MSVC_ONLY(&) write_five;
|
||||
v1 = v2;
|
||||
BOOST_TEST(!v1.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
Reference in New Issue
Block a user