用 std 实现替换 boost
Replacing boost with std implementation
正确的替换方法是什么:
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << boost::lambda::constant(" ") << boost::lambda::_1);
使用不使用 boost 的实现?这是我试过的:
std::string backspace("&nbps;");
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << backspace << std::placeholders::_1);
第二个“<<”带有红色下划线,我收到错误消息:
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 的奇妙怪兽。与您的代码等效的是:
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::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << boost::lambda::constant(" ") << boost::lambda::_1);
使用不使用 boost 的实现?这是我试过的:
std::string backspace("&nbps;");
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << backspace << std::placeholders::_1);
第二个“<<”带有红色下划线,我收到错误消息:
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 的奇妙怪兽。与您的代码等效的是:
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;