用std实施取代boost [英] Replacing boost with std implementation
本文介绍了用std实施取代boost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是替代此方法的正确方法?
What is the correct way to replace this:
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << boost::lambda::constant(" ") << boost::lambda::_1);
使用不使用boost的实现吗?这是我尝试过的:
With an implementation that doesn't use boost? This is what I've tried:
std::string backspace("&nbps;");
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << backspace << std::placeholders::_1);
第二个'<<'用红色下划线显示,我收到错误消息:
The second '<<' is underlined in red and I get the error message:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_Ph<1>' (or there is no acceptable conversion)
推荐答案
boost :: lambda
是一种奇妙的怪兽,它会将lambda反向移植到C ++ 03.与您的代码等效的是:
boost::lambda
is a marvellous monstrosity that kind of backported lambdas to C++03. The equivalent to your code is:
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), [&](auto const &v) { buf << " " << v; });
...甚至:
std::ostringstream buf;
for(auto const &v : bd)
buf << " " << v;
这篇关于用std实施取代boost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文