简体   繁体   English

提高accumulator_set:期望主表达式

[英]boost accumulator_set: expect primary expression

I am a new to Boost library. 我是Boost库的新手。 I want a program that could compute the min, max, mean and variance of a distance vector (of type std::vector < double > ) and I wrote the following code 我想要一个可以计算距离矢量(类型为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;

But the program gives me an error at line std::for_each(dist_err.begin(), dist_err.end(), boost::bind < void > (boost::ref(stat_acc), boost::mpl::placeholders::_1)); 但是程序在std::for_each(dist_err.begin(), dist_err.end(), boost::bind < void > (boost::ref(stat_acc), boost::mpl::placeholders::_1)); and it says 它说

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));

Could someone please give me some hint on how to solve this error? 有人可以给我一些有关如何解决此错误的提示吗?

The problem is you are using boost::mpl::placeholders::_1 inside code which doesn't use MPL. 问题是您在不使用MPL的内部代码中使用boost::mpl::placeholders::_1 Instead, just say _1 . 而是说_1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM