我创建了一个使用boost库测试框架的单元测试,并遇到了使用std :: bind占位符以及所述库的问题。使用std :: bind占位符和boost库的问题
如果我明确地使用std::placeholders::
+ _1,它工作正常:
std::bind(&TestFixture::concatStrings, this, std::placeholders::_1, std::placeholders::_2)
但是,如果我省略了std::placeholders::
并直接使用_1
,它会导致一个编译错误:
Error 1 error C2664: 'std::string std::_Pmf_wrap<std::string (__thiscall TestFixture::*)(const std::string &,const std::string &),std::string,TestFixture,const std::string &,const std::string &>::operator()(_Farg0 &,const std::string &,const std::string &) const' : cannot convert argument 2 from 'boost::arg<1>' to 'const std::string &' C:\APPS\msvs2013\VC\include\functional 1149 1 test
使用lambda ,是我能想到的最佳解决方案:
[&](const std::string& x, const std::string& y){ return concatStrings(x, y); }
我只是想了解如果使用std中定义的方法定义std冲突与boost库,如std :: bind。提前致谢。
嗨!感谢您的回复。使用'_1'可以很好地与boost :: bind配合使用。虽然,如果我要明确使用std :: bind,我应该使用'std :: placeholders :: _ 1'。感谢您指出lambda中的捕获,我会习惯于安全地选择我的捕获。 :) – cawols