SPl*_*ten 4 c++ boost std c++11
替换它的正确方法是什么:
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << boost::lambda::constant(" ") << boost::lambda::_1);
Run Code Online (Sandbox Code Playgroud)
使用不使用 boost 的实现?这是我尝试过的:
std::string backspace("&nbps;");
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << backspace << std::placeholders::_1);
Run Code Online (Sandbox Code Playgroud)
第二个 '<<' 用红色下划线表示,我收到错误消息:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_Ph<1>' (or there is no acceptable conversion)
Run Code Online (Sandbox Code Playgroud)
boost::lambda是一个奇妙的怪物,将 lambdas 反向移植到 C++03。相当于您的代码是:
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), [&](auto const &v) { buf << " " << v; });
Run Code Online (Sandbox Code Playgroud)
... 甚至:
std::ostringstream buf;
for(auto const &v : bd)
buf << " " << v;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
119 次 |
| 最近记录: |