2016-11-26 14 views
1

저는 Boost 라이브러리에 처음 입니다. 나는 분을 계산할 수있는 프로그램이 최대가 의미하고 (유형 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

안녕하세요, John 작품입니다! 답장을 보내 주셔서 대단히 감사합니다. 그러나 나는 아직도 조금 혼란 스럽다. '_1'이 어디서 왔는지, 그게 무슨 뜻인지 설명해 주시겠습니까? –

+0

@BojianZheng :'_1'은 Boost에서 왔지만, boost ::'네임 스페이스에는 없습니다. 또한'std :: bind()'가있는 C++ 11 표준의 일부이기도합니다. 그것이 의미하는 바를 알고 싶다면 문서를 읽으십시오. –