|
Boost : |
Subject: Re: [boost] [bind] Boost.Bind compile error with msvc-11 and msvc-10
From: Peter Dimov (lists_at_[hidden])
Date: 2013-02-13 09:54:54
Ian Emmons wrote:
> I have attached a short, self-contained test case that uses Boost.Bind.
> this test case compiles and runs correctly with the following tool sets:
>
> darwin (gcc 4.2.1 on MacOS 10.8)
> clang (clang on MacOS 10.8)
> gcc (gcc 4.7 on Ubuntu 12.04)
> msvc-9 (Visual Studio 2008 on Windows 7)
>
> It fails to compile on these:
>
> msvc-11 (Visual Studio 2012 on Windows 7)
> msvc-10 (Visual Studio 2010 on Windows 7)
>
> I have also attached the error messages from msvc-11, which seem to
> indicate that Boost.Bind is the problem. Can anyone shed any light on
> this issue?
The problem is that vector<>::push_back is overloaded in C++11 to take an
rvalue reference, and bind generally doesn't work with overloaded functions
(although boost::bind does if they differ in their number of parameters,
which is unfortunately not the case here). If you ignore all the "expects X
parameters" errors, this is the relevant one:
ATestCase.cpp(36) : error C2784:
'boost::_bi::bind_t<Rt2,boost::_mfi::cmf0<R,T>,_bi::list_av_1<A1>::type>
boost::bind(boost::type<T>,R (__cdecl T::* )(void) const,A1)' : could not
deduce template argument for 'overloaded function type' from 'overloaded
function type'
Fixing this is not particularly elegant. To select an overload, you need to
do something like
void (X::StringList::*pmf)(string const&) = &X::StringList::push_back;
x.enumerateStrings(::boost::bind(pmf, &strList, _1));
(You'll get the same error with g++ if you use -std=c++11, by the way.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk