Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-11-21 14:18:28


Christopher Currie <christopher_at_[hidden]> writes:

> Peter Dimov wrote:
>> That's odd. This is the line that fails:
>> BOOST_TEST( bind(&X::hash, _1)(x) == 23558 );
>> and the error message seems to indicate that the overload
>> template<class F, class A1>
>> _bi::bind_t<_bi::unspecified, F, typename _bi::list_av_1<A1>::type>
>> BOOST_BIND(F f, A1 a1)
>> is (incorrectly) preferred over
>> template<class R, class T, class A1>
>> _bi::bind_t< R const &, _mfi::dm<R, T>, typename _bi::list_av_1<A1>::type >
>> BOOST_BIND(R T::*f, A1 a1)
>
> That helps. Here's the test case that makes it fail:
>
> struct unspecified {};
>
> template<class R> class bind_t { };
>
> template<class R, class F>
> bind_t<R>
> bind(F f);
>
> template<class F>
> bind_t<unspecified>
> bind(F f);
>
> template<class R, class T>
> bind_t<R const &>
> bind(R T::* pm)
> {
> return bind_t<R const &>();
> }
>
> struct X { int i; };
>
> int main() { bind(&X::i); }
>
>
> The Sun compiler is selecting the first partial specialization over
> the second. If I comment out the first specialization, the code
> compiles fine, but for some reason it thinks the first is a better
> match, so it won't link.

These are overloads, not partial specializations, but anyway...

> Is this something we can work around, or is this something the user
> will just have to deal with? I can specify "bind<int, X>(&X::i)" in
> main, and it will compile.

what happens if you reverse their order?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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