Boost Accumulator_SET:期望主表达式

boost accumulator_set: expect primary expression

本文关键字:期望 表达式 SET Accumulator Boost      更新时间:2023-10-16

我是提升库的新手。我想要一个可以计算距离向量(类型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