Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-18 08:45:53


Douglas Gregor wrote:
> On Mar 13, 2005, at 12:28 PM, Peter Dimov wrote:
>
>> The reason I'm posting this is that I just switched boost::bind to
>> implement function_equal instead of operator==, and this
>> functionality isn't covered by our current tests.
>
> I've added more tests to cover this.

This:

namespace boost {
  bool function_equal(const ReturnIntFE& x, const ReturnIntFE& y)
  { return x.value == y.value; }
}

is the proper way to define function_equal on compilers that do not have
argument dependent lookup. It will fail on conforming compilers because of
two-phase lookup in templates. When ADL is supported, function_equal should
be defined in the namespace of the class (ReturnIntFE in this case).

This is still not the whole story. On compilers that do not implement
partial function template ordering, we need to define function_equal_impl
instead, if the class is a template (the rule that nontemplates beat
templates will save us in the above example).

This is how bind defines its function_equal, taking into account all of
these factors:

// function_equal

#ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP

// put overloads in _bi, rely on ADL

# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING

template<class R, class F, class L> bool function_equal( bind_t<R, F, L>
const & a, bind_t<R, F, L> const & b )
{
    return a.compare(b);
}

# else

template<class R, class F, class L> bool function_equal_impl( bind_t<R, F,
L> const & a, bind_t<R, F, L> const & b, int )
{
    return a.compare(b);
}

# endif // #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING

#else // BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP

// put overloads in boost

} // namespace _bi

# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING

template<class R, class F, class L> bool function_equal( _bi::bind_t<R, F,
L> const & a, _bi::bind_t<R, F, L> const & b )
{
    return a.compare(b);
}

# else

template<class R, class F, class L> bool function_equal_impl( _bi::bind_t<R,
F, L> const & a, _bi::bind_t<R, F, L> const & b, int )
{
    return a.compare(b);
}

# endif // #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING

namespace _bi
{

#endif // BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP

"Great", I hear you saying. ;-) Such is life in broken-compiler-land. The
function_equal tests should probably be moved to their own
contains_fe_test.cpp in order to not introduce "fake" regressions in
contains_test.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk