forked from boostorg/function
function_template.hpp, function_base.hpp:
- Comparison operators are now written in terms of function_base so that implicit conversions to function<...> or functionN<...> don't allow arbitrary comparisons. [SVN r23126]
This commit is contained in:
@ -493,6 +493,117 @@ inline bool operator!=(detail::function::useless_clear_type*,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_NO_SFINAE
|
||||
// Comparisons between boost::function objects and arbitrary function objects
|
||||
template<typename Functor>
|
||||
inline bool operator==(const function_base& f, Functor g)
|
||||
{
|
||||
typedef mpl::bool_<(is_integral<Functor>::value)> integral;
|
||||
return detail::function::compare_equal(f, g, 0, integral());
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
inline bool operator==(Functor g, const function_base& f)
|
||||
{
|
||||
typedef mpl::bool_<(is_integral<Functor>::value)> integral;
|
||||
return detail::function::compare_equal(f, g, 0, integral());
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
inline bool operator!=(const function_base& f, Functor g)
|
||||
{
|
||||
typedef mpl::bool_<(is_integral<Functor>::value)> integral;
|
||||
return detail::function::compare_not_equal(f, g, 0, integral());
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
inline bool operator!=(Functor g, const function_base& f)
|
||||
{
|
||||
typedef mpl::bool_<(is_integral<Functor>::value)> integral;
|
||||
return detail::function::compare_not_equal(f, g, 0, integral());
|
||||
}
|
||||
#else
|
||||
|
||||
#define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
|
||||
typename ::boost::enable_if_c<(::boost::type_traits::ice_not< \
|
||||
(::boost::is_integral<Functor>::value)>::value), \
|
||||
Type>::type
|
||||
|
||||
// Comparisons between boost::function objects and arbitrary function objects
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator==(const function_base& f, Functor g)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return function_equal(*fp, g);
|
||||
else return false;
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator==(Functor g, const function_base& f)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return function_equal(g, *fp);
|
||||
else return false;
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator!=(const function_base& f, Functor g)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return !function_equal(*fp, g);
|
||||
else return true;
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator!=(Functor g, const function_base& f)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return !function_equal(g, *fp);
|
||||
else return true;
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator==(const function_base& f, reference_wrapper<Functor> g)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return fp == g.get_pointer();
|
||||
else return false;
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator==(reference_wrapper<Functor> g, const function_base& f)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return g.get_pointer() == fp;
|
||||
else return false;
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator!=(const function_base& f, reference_wrapper<Functor> g)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return fp != g.get_pointer();
|
||||
else return true;
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator!=(reference_wrapper<Functor> g, const function_base& f)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return g.get_pointer() != fp;
|
||||
else return true;
|
||||
}
|
||||
#undef BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL
|
||||
#endif // Compiler supporting SFINAE
|
||||
|
||||
namespace detail {
|
||||
namespace function {
|
||||
inline bool has_empty_target(const function_base* f)
|
||||
|
@ -578,181 +578,6 @@ template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>&);
|
||||
|
||||
#ifdef BOOST_NO_SFINAE
|
||||
// Comparisons between boost::function objects and arbitrary function objects
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
inline bool
|
||||
operator==(const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f,
|
||||
Functor g)
|
||||
{
|
||||
typedef mpl::bool_<(is_integral<Functor>::value)> integral;
|
||||
return detail::function::compare_equal(f, g, 0, integral());
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
inline bool
|
||||
operator==(Functor g,
|
||||
const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f)
|
||||
{
|
||||
typedef mpl::bool_<(is_integral<Functor>::value)> integral;
|
||||
return detail::function::compare_equal(f, g, 0, integral());
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
inline bool
|
||||
operator!=(const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f,
|
||||
Functor g)
|
||||
{
|
||||
typedef mpl::bool_<(is_integral<Functor>::value)> integral;
|
||||
return detail::function::compare_not_equal(f, g, 0, integral());
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
inline bool
|
||||
operator!=(Functor g,
|
||||
const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f)
|
||||
{
|
||||
typedef mpl::bool_<(is_integral<Functor>::value)> integral;
|
||||
return detail::function::compare_not_equal(f, g, 0, integral());
|
||||
}
|
||||
#else
|
||||
|
||||
#define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
|
||||
typename ::boost::enable_if_c<(::boost::type_traits::ice_not< \
|
||||
(::boost::is_integral<Functor>::value)>::value), \
|
||||
Type>::type
|
||||
|
||||
// Comparisons between boost::function objects and arbitrary function objects
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator==(const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f,
|
||||
Functor g)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return function_equal(*fp, g);
|
||||
else return false;
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator==(Functor g,
|
||||
const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return function_equal(g, *fp);
|
||||
else return false;
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator!=(const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f,
|
||||
Functor g)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return !function_equal(*fp, g);
|
||||
else return true;
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator!=(Functor g,
|
||||
const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return !function_equal(g, *fp);
|
||||
else return true;
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator==(const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f,
|
||||
reference_wrapper<Functor> g)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return fp == g.get_pointer();
|
||||
else return false;
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator==(reference_wrapper<Functor> g,
|
||||
const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return g.get_pointer() == fp;
|
||||
else return false;
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator!=(const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f,
|
||||
reference_wrapper<Functor> g)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return fp != g.get_pointer();
|
||||
else return true;
|
||||
}
|
||||
|
||||
template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS ,
|
||||
typename Allocator, typename Functor>
|
||||
BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)
|
||||
operator!=(reference_wrapper<Functor> g,
|
||||
const BOOST_FUNCTION_FUNCTION<
|
||||
R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS ,
|
||||
Allocator>& f)
|
||||
{
|
||||
if (const Functor* fp = f.template target<Functor>())
|
||||
return g.get_pointer() != fp;
|
||||
else return true;
|
||||
}
|
||||
#undef BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL
|
||||
#endif // Compiler supporting SFINAE
|
||||
|
||||
#if !defined(BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX)
|
||||
|
||||
#if BOOST_FUNCTION_NUM_ARGS == 0
|
||||
|
Reference in New Issue
Block a user