c++ - boost accumulator_set : expect primary expression

标签 c++ boost boost-bind boost-mpl boost-accumulators

我是 Boost 库的新手。我想要一个可以计算距离 vector (类型 std::vector < double > )的最小值、最大值、均值和方差的程序,我编写了以下代码

std::vector < double > dist_err;
// ... do something with dist_err
boost::accumulators::accumulator_set
< 
    double, 
    boost::accumulators::stats
    <
        boost::accumulators::tag::min , 
        boost::accumulators::tag::max ,
        boost::accumulators::tag::mean,
        boost::accumulators::tag::variance
    > 
> stat_acc;
std::for_each(dist_err.begin(), dist_err.end(), boost::bind < void > (boost::ref(stat_acc), boost::mpl::placeholders::_1));
std::cout << "min[distance error]: " << boost::accumulators::min      (stat_acc) << std::endl;
std::cout << "MAX[distance error]: " << boost::accumulators::max      (stat_acc) << std::endl;
std::cout << "  E[distance error]: " << boost::accumulators::mean     (stat_acc) << std::endl;
std::cout << "VAR[distance error]: " << boost::accumulators::variance (stat_acc) << std::endl;

但是程序在 std::for_each(dist_err.begin(), dist_err.end(), boost::bind < void > (boost::ref(stat_acc), boost::mpl::placeholders::_1)); 行给我一个错误它说

error: expected primary-expression before ')' token
std::for_each(dist_err.begin(), dist_err.end(), boost::bind < void > (boost::ref(stat_acc), boost::mpl::placeholders::_1));

有人可以给我一些关于如何解决这个错误的提示吗?

最佳答案

问题是您在不使用 MPL 的代码中使用 boost::mpl::placeholders::_1。相反,只需说 _1

关于c++ - boost accumulator_set : expect primary expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40814703/

相关文章:

c++ - Boost绑定(bind)并分配以将 vector 转换为字符串

c++ - 从 std::string 中按字节提取连续位并带有位偏移量

c++ - 是否可以通过在 matlab 中调用 c/c++ 代码来加速 matlab 绘图?

c++ - Boost::GIL 'jpeglib.h':没有那个文件或目录

c++ - boost::asio io_service 保留我的其余代码运行

c++ - 有没有办法找出一个类是否是另一个类的直接基础?

python - 地址清理 Boost.Python 模块

c++ - Floating/Embedded QDockWidget in a QWidget (KXmlGuiWindow's CentralWidget designed in QT Designer)

c++ - 使用 boost::function::target 获取函数指针时的空指针

c++ - 使用 STL/Boost/Lambdas 调整映射迭代器