Added contains() and function_equal()

[SVN r22483]
This commit is contained in:
Douglas Gregor
2004-03-12 03:38:20 +00:00
parent e80a00545c
commit 2c0e633307
5 changed files with 111 additions and 15 deletions

View File

@ -1,6 +1,6 @@
// Boost.Function library
// Copyright Doug Gregor 2001-2003. Use, modification and
// Copyright Doug Gregor 2001-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@ -28,6 +28,7 @@
#else
# include "boost/mpl/bool.hpp"
#endif
#include <boost/function_equal.hpp>
// Borrowed from Boost.Python library: determines the cases where we
// need to use std::type_info::name to compare instead of operator==.
@ -336,7 +337,7 @@ namespace boost {
mpl::bool_<false>)
{
if (const Functor* fp = f.template target<Functor>())
return *fp == g;
return function_equal(*fp, g);
else return false;
}
@ -356,7 +357,7 @@ namespace boost {
mpl::bool_<false>)
{
if (const Functor* fp = f.template target<Functor>())
return *fp != g;
return !function_equal(*fp, g);
else return true;
}
@ -421,6 +422,16 @@ public:
}
}
template<typename F>
bool contains(const F& f) const
{
if (const F* fp = this->template target<F>()) {
return function_equal(*fp, f);
} else {
return false;
}
}
public: // should be protected, but GCC 2.95.3 will fail to allow access
detail::function::any_pointer (*manager)(
detail::function::any_pointer,

View File

@ -648,7 +648,8 @@ template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
Allocator>& f,
Functor g)
{
if (const Functor* fp = f.template target<Functor>()) return *fp == g;
if (const Functor* fp = f.template target<Functor>())
return function_equal(*fp, g);
else return false;
}
@ -661,7 +662,8 @@ template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
BOOST_FUNCTION_TEMPLATE_ARGS ,
Allocator>& f)
{
if (const Functor* fp = f.template target<Functor>()) return g == *fp;
if (const Functor* fp = f.template target<Functor>())
return function_equal(g, *fp);
else return false;
}
@ -674,7 +676,8 @@ template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
Allocator>& f,
Functor g)
{
if (const Functor* fp = f.template target<Functor>()) return *fp != g;
if (const Functor* fp = f.template target<Functor>())
return !function_equal(*fp, g);
else return true;
}
@ -687,7 +690,8 @@ template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
BOOST_FUNCTION_TEMPLATE_ARGS ,
Allocator>& f)
{
if (const Functor* fp = f.template target<Functor>()) return g != *fp;
if (const Functor* fp = f.template target<Functor>())
return !function_equal(g, *fp);
else return true;
}