forked from boostorg/function
Added contains() and function_equal()
[SVN r22483]
This commit is contained in:
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
24
include/boost/function_equal.hpp
Normal file
24
include/boost/function_equal.hpp
Normal file
@ -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<typename F, typename G>
|
||||
bool function_equal_impl(const F& f, const G& g, long)
|
||||
{ return f == g; }
|
||||
} // end namespace boost::function
|
||||
|
||||
template<typename F, typename G>
|
||||
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
|
Reference in New Issue
Block a user