Visual Studio 2010和的boost ::绑定 [英] Visual Studio 2010 and boost::bind

查看:122
本文介绍了Visual Studio 2010和的boost ::绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的一块code,它使用的boost ::绑定:

I have this simple piece of code that uses boost::bind:

#include <boost/bind.hpp>
#include <utility>
#include <vector>
#include <iterator>
#include <algorithm>

int main()
{
    std::vector<int> a;
    std::vector<std::pair<bool,int> > b;

    a.push_back(1);
    a.push_back(2);
    a.push_back(3);

    std::transform(a.begin(), a.end(), std::back_inserter(b),
                   boost::bind(std::make_pair<bool, int>, false, _1));
}

我收到一吨VS2010 RC的错误,如:

I'm getting a ton of errors in VS2010 RC, such as:

Error   1   error C2780: 'boost::_bi::bind_t<_bi::dm_result<MT::* ,A1>::type,boost::_mfi::dm<M,T>,_bi::list_av_1<A1>::type> boost::bind(M T::* ,A1)' : expects 2 arguments - 3 provided c:\projects\testtuple\main.cpp  18  
Error   2   error C2780: 'boost::_bi::bind_t<Rt2,boost::_mfi::cmf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,_bi::list_av_9<A1,A2,A3,A4,A5,A6,A7,A8,A9>::type> boost::bind(boost::type<T>,R (__thiscall T::* )(B1,B2,B3,B4,B5,B6,B7,B8) const,A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 11 arguments - 3 provided   c:\projects\testtuple\main.cpp  18

我是不是做错了什么?如果这是在编译器中的错误,我怎么能解决方法呢?

Am I doing something wrong? If this is a bug in the compiler, how can I workaround it?

编辑:增加了整个测试用例

added the entire test case.

澄清:在code编译在VS2008

推荐答案

更新:

问题是, make_pair <​​/ code>似乎附带VS2010(这是不是在VS的previous版本或GCC)的STL超载。解决方法是作出明确要重载,具有投:

The problem is that make_pair seems to be overloaded in the STL that ships with VS2010 (it wasn't in previous versions of VS or in GCC). The workaround is to make explicit which of the overloads you want, with a cast:

#include <boost/bind.hpp>
#include <utility>
#include <vector>
#include <iterator>
#include <algorithm>


int main()
{
    std::vector<int> a;
    std::vector<std::pair<bool,int> > b;

    a.push_back(1);
    a.push_back(2);
    a.push_back(3);

    typedef std::pair<bool, int> (*MakePairType)(bool, int);

    std::transform(a.begin(), a.end(), std::back_inserter(b),
                    boost::bind((MakePairType)&std::make_pair<bool, int>,
                                false, _1));
}

有关更多详细信息,请参见提升绑定手动

For additional details see the Boost bind manual.

这篇关于Visual Studio 2010和的boost ::绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆