Boost::accumulators initialization failing on mac OSX Yosemite

277 Views Asked by At

I am currently trying to use Boost::accumulators, but getting compilation error while initializing in the constructor. Please check the class details below.

Environment:
Mac OSX Yosemite
G++ version: 
4.2.1
Boot Version: 1.55

Code:

class test
{
    public:
        test();
        test(unsigned char windowSize=5): acc(tag::rolling_window::window_size=windowSize){}
    protected:
        accumulator_set<unsigned short, stats<tag::rolling_mean > >  acc;
    private:
};

Error:

/usr/local/boost/include/boost/accumulators/statistics/rolling_window.hpp|49|error: no viable overloaded operator[] for type 'const boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator, boost::accumulators::accumulator_set<unsigned short, boost::accumulators::stats<boost::accumulators::tag::rolling_mean, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, void> >, boost::parameter::aux::empty_arg_list>'|

-----------
/usr/local/boost/include/boost/parameter/aux_/arg_list.hpp|346|note: candidate function not viable: no known conversion from 'keyword<tag::rolling_window_size>' to 'const keyword<key_type>' for 1st argument|
-------------------
2

There are 2 best solutions below

0
sehe On

You may lack some includes, leading to incomplete types in the initializer ET:

Live On Coliru

#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#include <boost/accumulators/statistics/rolling_window.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>
#include <iostream>

namespace ba = boost::accumulators;

class test
{
    public:
        test();
        test(unsigned char windowSize=5): acc(ba::tag::rolling_window::window_size = windowSize){}
    protected:
        ba::accumulator_set<unsigned short, ba::stats<ba::tag::rolling_mean > >  acc;
    private:
};

int main()
{
}
0
user5232024 On

Thanks for your message. I have already included all the required files, but it looks like having an overloaded constructors might be causing this. I have removed all the constructors and kept only one with initialization list and it started working. Thanks again.

Code:

#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#include <boost/accumulators/statistics/rolling_window.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>  
#include <iostream>
namespace ba = boost::accumulators;

class test
{
 public:
    test(unsigned char windowSize=5):         acc(ba::tag::rolling_window::window_size = windowSize){}
protected:
    ba::accumulator_set<unsigned short, ba::stats<ba::tag::rolling_mean > >    acc;
private:
};