mirror of
https://github.com/boostorg/function.git
synced 2025-07-24 18:07:15 +02:00
function.hpp:
- Use "self_type" instead of "function" for constructing swapping temporary (Borland C++ needs it) function_base.hpp: - Give empty copy constructor, default constructor, and assignment operator to empty_function_mixin (MSVC generates incorrect ones) function_template.hpp: - Make Borland C++ and MSVC agree on the code (involves an extra constructor definition and careful use of self_type vs. BOOST_FUNCTION_FUNCTION) [SVN r10619]
This commit is contained in:
@ -463,58 +463,58 @@ namespace boost {
|
|||||||
function(Functor* f) : base_type(f) {}
|
function(Functor* f) : base_type(f) {}
|
||||||
#endif // __BORLANDC__
|
#endif // __BORLANDC__
|
||||||
|
|
||||||
function(const function& f) : base_type(static_cast<const base_type&>(f)){}
|
function(const self_type& f) : base_type(static_cast<const base_type&>(f)){}
|
||||||
|
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
function& operator=(const Functor& f)
|
function& operator=(const Functor& f)
|
||||||
{
|
{
|
||||||
function(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
function& operator=(Functor* f)
|
self_type& operator=(Functor* f)
|
||||||
{
|
{
|
||||||
function(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif // __BORLANDC__
|
#endif // __BORLANDC__
|
||||||
|
|
||||||
function& operator=(const base_type& f)
|
self_type& operator=(const base_type& f)
|
||||||
{
|
{
|
||||||
function(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function& operator=(const function& f)
|
self_type& operator=(const self_type& f)
|
||||||
{
|
{
|
||||||
function(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
void set(const Functor& f)
|
void set(const Functor& f)
|
||||||
{
|
{
|
||||||
function(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
void set(Functor* f)
|
void set(Functor* f)
|
||||||
{
|
{
|
||||||
function(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
}
|
}
|
||||||
#endif // __BORLANDC__
|
#endif // __BORLANDC__
|
||||||
|
|
||||||
void set(const base_type& f)
|
void set(const base_type& f)
|
||||||
{
|
{
|
||||||
function(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(const function& f)
|
void set(const self_type& f)
|
||||||
{
|
{
|
||||||
function(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -397,8 +397,15 @@ namespace boost {
|
|||||||
inline void postcall(const function_base*) {}
|
inline void postcall(const function_base*) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The default function mixin costs nothing
|
// The default function mixin does nothing. The assignment and copy-construction operators
|
||||||
struct empty_function_mixin {};
|
// are all defined because MSVC defines broken versions.
|
||||||
|
struct empty_function_mixin {
|
||||||
|
empty_function_mixin() {};
|
||||||
|
empty_function_mixin(const empty_function_mixin&) {};
|
||||||
|
|
||||||
|
empty_function_mixin& operator=(const empty_function_mixin&)
|
||||||
|
{return *this; }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // BOOST_FUNCTION_BASE_HEADER
|
#endif // BOOST_FUNCTION_BASE_HEADER
|
||||||
|
@ -474,6 +474,7 @@ namespace boost {
|
|||||||
typedef Policy policy_type;
|
typedef Policy policy_type;
|
||||||
typedef Mixin mixin_type;
|
typedef Mixin mixin_type;
|
||||||
typedef Allocator allocator_type;
|
typedef Allocator allocator_type;
|
||||||
|
typedef BOOST_FUNCTION_FUNCTION self_type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
|
#ifdef BOOST_FUNCTION_USE_VIRTUAL_FUNCTIONS
|
||||||
@ -490,8 +491,17 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MSVC chokes if the following two constructors are collapsed into
|
||||||
|
// one with a default parameter.
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
BOOST_FUNCTION_FUNCTION(const Functor& f, const Mixin& m = Mixin()) :
|
BOOST_FUNCTION_FUNCTION(const Functor& f) :
|
||||||
|
function_base(), Mixin() BOOST_FUNCTION_INIT
|
||||||
|
{
|
||||||
|
this->assign_to(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Functor>
|
||||||
|
BOOST_FUNCTION_FUNCTION(const Functor& f, const Mixin& m) :
|
||||||
function_base(), Mixin(m) BOOST_FUNCTION_INIT
|
function_base(), Mixin(m) BOOST_FUNCTION_INIT
|
||||||
{
|
{
|
||||||
this->assign_to(f);
|
this->assign_to(f);
|
||||||
@ -556,10 +566,15 @@ namespace boost {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The distinction between when to use BOOST_FUNCTION_FUNCTION and
|
||||||
|
// when to use self_type is obnoxious. MSVC cannot handle self_type as
|
||||||
|
// the return type of these assignment operators, but Borland C++ cannot
|
||||||
|
// handle BOOST_FUNCTION_FUNCTION as the type of the temporary to
|
||||||
|
// construct.
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
BOOST_FUNCTION_FUNCTION& operator=(const Functor& f)
|
BOOST_FUNCTION_FUNCTION& operator=(const Functor& f)
|
||||||
{
|
{
|
||||||
BOOST_FUNCTION_FUNCTION(f, static_cast<const Mixin&>(*this)).swap(*this);
|
self_type(f, static_cast<const Mixin&>(*this)).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +582,7 @@ namespace boost {
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
BOOST_FUNCTION_FUNCTION& operator=(Functor* f)
|
BOOST_FUNCTION_FUNCTION& operator=(Functor* f)
|
||||||
{
|
{
|
||||||
BOOST_FUNCTION_FUNCTION(f, static_cast<const Mixin&>(*this)).swap(*this);
|
self_type(f, static_cast<const Mixin&>(*this)).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif // __BORLANDC__
|
#endif // __BORLANDC__
|
||||||
@ -575,14 +590,14 @@ namespace boost {
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
void set(const Functor& f)
|
void set(const Functor& f)
|
||||||
{
|
{
|
||||||
BOOST_FUNCTION_FUNCTION(f, static_cast<const Mixin&>(*this)).swap(*this);
|
self_type(f, static_cast<const Mixin&>(*this)).swap(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
void set(Functor* f)
|
void set(Functor* f)
|
||||||
{
|
{
|
||||||
BOOST_FUNCTION_FUNCTION(f, static_cast<const Mixin&>(*this)).swap(*this);
|
self_type(f, static_cast<const Mixin&>(*this)).swap(*this);
|
||||||
}
|
}
|
||||||
#endif // __BORLANDC__
|
#endif // __BORLANDC__
|
||||||
|
|
||||||
@ -592,7 +607,7 @@ namespace boost {
|
|||||||
if (&f == this)
|
if (&f == this)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
BOOST_FUNCTION_FUNCTION(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,7 +617,7 @@ namespace boost {
|
|||||||
if (&f == this)
|
if (&f == this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BOOST_FUNCTION_FUNCTION(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(BOOST_FUNCTION_FUNCTION& other)
|
void swap(BOOST_FUNCTION_FUNCTION& other)
|
||||||
|
Reference in New Issue
Block a user