2016-11-26 8 views
1

私はBoostライブラリの初心者です。私は、MIN、MAXを計算することができ、プログラムをしたい、意味及び(タイプstd::vector <double>の)距離ベクトルの分散と、私は次のコードboost accumulator_set:一次式が期待されます

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

このエラーを解決する方法のヒントを教えてください。

答えて

2

問題は、MPLを使用しないコード内にboost::mpl::placeholders::_1を使用していることです。代わりに、_1と言うだけです。

+0

こんにちはジョン、それは動作します!あなたの返事をありがとうございました。しかし、私はまだちょっと混乱しています...「_1」はどこから来たのか、そしてそれは何を意味するのかを説明してください。 –

+0

@BojianZheng: '_1'はBoostから来ますが、' boost :: '名前空間にはありません。また、 'std :: bind()'を持つC++ 11標準の一部です。それが何を意味しているか知りたければ、ドキュメントを読んでください。 –

関連する問題