function_template.hpp:

- function partial specialization now allows assignment to zero
    (for clearing) and comparison against zero (for the empty check)
    (Brad King)

function_test.cpp:
  - Check comparison against zero
  - Check assignment to zero

function_test_fail1.cpp:
function_test_fail2.cpp:
  - Make them fail for the right reasons


[SVN r15803]
This commit is contained in:
Douglas Gregor
2002-10-08 02:32:38 +00:00
parent 300fde19a1
commit 374711d2c6
4 changed files with 54 additions and 31 deletions

View File

@ -533,6 +533,11 @@ class function<BOOST_FUNCTION_PARTIAL_SPEC, Allocator>
BOOST_FUNCTION_COMMA Allocator> base_type;
typedef function self_type;
struct clear_type {};
class holder;
friend class holder;
public:
typedef typename base_type::allocator_type allocator_type;
@ -543,26 +548,44 @@ public:
function(const self_type& f) : base_type(static_cast<const base_type&>(f)){}
template<typename Functor>
self_type& operator=(Functor BOOST_FUNCTION_TARGET_FIX(const &) f)
self_type& operator=(self_type& f)
{
self_type(f).swap(*this);
return *this;
}
self_type& operator=(const base_type& f)
{
self_type(f).swap(*this);
return *this;
}
inline self_type& operator=(holder h);
self_type& operator=(const self_type& f)
self_type& operator=(clear_type*)
{
self_type(f).swap(*this);
this->clear();
return *this;
}
};
template<typename R BOOST_FUNCTION_COMMA
BOOST_FUNCTION_TEMPLATE_PARMS,
typename Allocator>
class function<BOOST_FUNCTION_PARTIAL_SPEC, Allocator>::holder
{
public:
template<typename F> holder(F f) : func(f) {}
holder(const base_type& f) : func(f) {}
holder(const self_type& f) : func(f) {}
self_type func;
};
template<typename R BOOST_FUNCTION_COMMA
BOOST_FUNCTION_TEMPLATE_PARMS,
typename Allocator>
function<BOOST_FUNCTION_PARTIAL_SPEC, Allocator>&
function<BOOST_FUNCTION_PARTIAL_SPEC, Allocator>::operator=(holder h)
{
h.func.swap(*this);
return *this;
}
#undef BOOST_FUNCTION_PARTIAL_SPEC
#endif // have partial specialization