diff --git a/include/boost/function.hpp b/include/boost/function.hpp index 462f518..c43c176 100644 --- a/include/boost/function.hpp +++ b/include/boost/function.hpp @@ -456,56 +456,35 @@ namespace boost { function() : base_type() {} template - function(const Functor& f) : base_type(f) {} + function(Functor BOOST_MSVC_ONLY(const &) f) : base_type(f) {} -#ifdef __BORLANDC__ - template function(Functor* f) : base_type(f) {} -#endif // __BORLANDC__ - function(const self_type& f) : base_type(static_cast(f)){} template - function& operator=(const Functor& f) + self_type& operator=(Functor BOOST_MSVC_ONLY(const &) f) { self_type(f).swap(*this); return *this; } -#ifdef __BORLANDC__ - template - 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 - void set(const Functor& f) + void set(Functor BOOST_MSVC_ONLY(const &) f) { self_type(f).swap(*this); } -#ifdef __BORLANDC__ - template - void set(Functor* f) - { - self_type(f).swap(*this); - } -#endif // __BORLANDC__ - void set(const base_type& f) { self_type(f).swap(*this); diff --git a/include/boost/function/function_base.hpp b/include/boost/function/function_base.hpp index bca9269..26901c2 100644 --- a/include/boost/function/function_base.hpp +++ b/include/boost/function/function_base.hpp @@ -25,6 +25,12 @@ #include #include +#ifdef BOOST_MSVC +# define BOOST_MSVC_ONLY(x) x +#else +# define BOOST_MSVC_ONLY(x) +#endif // not MSVC + namespace boost { namespace detail { namespace function { diff --git a/include/boost/function/function_template.hpp b/include/boost/function/function_template.hpp index 676a6ec..231cfef 100644 --- a/include/boost/function/function_template.hpp +++ b/include/boost/function/function_template.hpp @@ -203,23 +203,14 @@ namespace boost { // MSVC chokes if the following two constructors are collapsed into // one with a default parameter. template - 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 - BOOST_FUNCTION_FUNCTION(Functor* f) : - function_base(), Mixin(), invoker(0) - { - this->assign_to(f); - } -#endif // __BORLANDC__ - - template - 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 - BOOST_FUNCTION_FUNCTION& operator=(const Functor& f) + BOOST_FUNCTION_FUNCTION& operator=(Functor f) { self_type(f, static_cast(*this)).swap(*this); return *this; } -#ifdef __BORLANDC__ template - BOOST_FUNCTION_FUNCTION& operator=(Functor* f) - { - self_type(f, static_cast(*this)).swap(*this); - return *this; - } -#endif // __BORLANDC__ - - template - void set(const Functor& f) + void set(Functor f) { self_type(f, static_cast(*this)).swap(*this); } -#ifdef __BORLANDC__ - template - void set(Functor* f) - { - self_type(f, static_cast(*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 - void assign_to(const Functor& f) + void assign_to(Functor f) { typedef typename detail::function::get_function_tag::type tag; this->assign_to(f, tag()); @@ -356,7 +330,9 @@ namespace boost { manager = &detail::function::functor_manager::manage; functor = manager(detail::function::any_pointer( - reinterpret_cast(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 - 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 diff --git a/test/function_n_test.cpp b/test/function_n_test.cpp index d528ca8..acd0c54 100644 --- a/test/function_n_test.cpp +++ b/test/function_n_test.cpp @@ -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 diff --git a/test/function_test.cpp b/test/function_test.cpp index f605aa0..6c87d0f 100644 --- a/test/function_test.cpp +++ b/test/function_test.cpp @@ -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());