diff --git a/doc/reference.xml b/doc/reference.xml
index 661a1e8..a734fd7 100644
--- a/doc/reference.xml
+++ b/doc/reference.xml
@@ -106,6 +106,18 @@
Will not throw.
+
+
+
+
+
+ bool
+
+ const Functor&
+
+ true
if this->target<Functor>()
is non-NULL and function_equal(*(this->target<Functor>()), f)
+
+
@@ -262,6 +274,18 @@
Will not throw.
+
+
+
+
+
+ bool
+
+ const Functor&
+
+ true
if this->target<Functor>()
is non-NULL and function_equal(*(this->target<Functor>()), f)
+
+
@@ -377,8 +401,9 @@
g
is not of type
reference_wrapper<Functor>
- and *(f.target<Functor>()) ==
- g
.
+ and
+ function_equal(*(f.target<Functor>()),
+ g)
.
@@ -479,8 +504,7 @@
g
is not of type
reference_wrapper<Functor>
- and *(f.target<Functor>()) !=
- g
.
+ and !function_equal(*(f.target<Functor>()), g)
.
@@ -672,6 +696,18 @@
pointer.
Will not throw.
+
+
+
+
+
+ bool
+
+ const Functor&
+
+ true
if this->target<Functor>()
is non-NULL and function_equal(*(this->target<Functor>()), f)
+
+
@@ -766,8 +802,7 @@
g
is not of type
reference_wrapper<Functor>
- and *(f.target<Functor>()) ==
- g
.
+ and function_equals(*(f.target<Functor>()), g)
.
@@ -850,8 +885,7 @@
g
is not of type
reference_wrapper<Functor>
- and *(f.target<Functor>()) !=
- g
.
+ and !function_equals(*(f.target<Functor>()), g)
.
@@ -871,4 +905,25 @@
+
+
+
+
+
+
+
+
+ bool
+
+ const F&
+
+
+ const G&
+
+ Compare two function objects for equality.
+ f == g
.
+ Only if f == g
throws.
+
+
+
diff --git a/include/boost/function/function_base.hpp b/include/boost/function/function_base.hpp
index fc57e66..21cc2f5 100644
--- a/include/boost/function/function_base.hpp
+++ b/include/boost/function/function_base.hpp
@@ -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
// 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_)
{
if (const Functor* fp = f.template target())
- return *fp == g;
+ return function_equal(*fp, g);
else return false;
}
@@ -356,7 +357,7 @@ namespace boost {
mpl::bool_)
{
if (const Functor* fp = f.template target())
- return *fp != g;
+ return !function_equal(*fp, g);
else return true;
}
@@ -421,6 +422,16 @@ public:
}
}
+ template
+ bool contains(const F& f) const
+ {
+ if (const F* fp = this->template target()) {
+ 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,
diff --git a/include/boost/function/function_template.hpp b/include/boost/function/function_template.hpp
index ca124d0..4c78303 100644
--- a/include/boost/function/function_template.hpp
+++ b/include/boost/function/function_template.hpp
@@ -648,7 +648,8 @@ template& f,
Functor g)
{
- if (const Functor* fp = f.template target()) return *fp == g;
+ if (const Functor* fp = f.template target())
+ return function_equal(*fp, g);
else return false;
}
@@ -661,7 +662,8 @@ template& f)
{
- if (const Functor* fp = f.template target()) return g == *fp;
+ if (const Functor* fp = f.template target())
+ return function_equal(g, *fp);
else return false;
}
@@ -674,7 +676,8 @@ template& f,
Functor g)
{
- if (const Functor* fp = f.template target()) return *fp != g;
+ if (const Functor* fp = f.template target())
+ return !function_equal(*fp, g);
else return true;
}
@@ -687,7 +690,8 @@ template& f)
{
- if (const Functor* fp = f.template target()) return g != *fp;
+ if (const Functor* fp = f.template target())
+ return !function_equal(g, *fp);
else return true;
}
diff --git a/include/boost/function_equal.hpp b/include/boost/function_equal.hpp
new file mode 100644
index 0000000..511504a
--- /dev/null
+++ b/include/boost/function_equal.hpp
@@ -0,0 +1,24 @@
+// Copyright Doug Gregor 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)
+
+// For more information, see http://www.boost.org
+#ifndef BOOST_FUNCTION_EQUAL_HPP
+#define BOOST_FUNCTION_EQUAL_HPP
+
+namespace boost {
+
+namespace detail {
+ template
+ bool function_equal_impl(const F& f, const G& g, long)
+ { return f == g; }
+} // end namespace boost::function
+
+template
+ bool function_equal(const F& f, const G& g)
+ { return ::boost::detail::function_equal_impl(f, g, 0); }
+
+} // end namespace boost
+
+#endif // BOOST_FUNCTION_EQUAL_HPP
diff --git a/test/contains_test.cpp b/test/contains_test.cpp
index 258e7a9..02f0ece 100644
--- a/test/contains_test.cpp
+++ b/test/contains_test.cpp
@@ -59,6 +59,7 @@ static void equal_test()
BOOST_TEST(&forty_two == f);
BOOST_TEST(f != ReturnInt(17));
BOOST_TEST(ReturnInt(17) != f);
+ BOOST_TEST(f.contains(&forty_two));
f = ReturnInt(17);
BOOST_TEST(f != &forty_two);
@@ -67,6 +68,7 @@ static void equal_test()
BOOST_TEST(ReturnInt(17) == f);
BOOST_TEST(f != ReturnInt(16));
BOOST_TEST(ReturnInt(16) != f);
+ BOOST_TEST(f.contains(ReturnInt(17)));
#if !defined(BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX)
boost::function g;