c++ - 将 boostaccumulator_set 存储在 STL 映射中

标签 c++ boost dictionary

我想在 STL map 中存储多个 boost Accumulataor_set。

我读到的所有示例都使用 accumulator_set作为局部变量:

accumulator_set<int, stats<tag::rolling_mean> > acc(tag::rolling_window::window_size = 5);

acc(1);
acc(2);
acc(3);

cout << rolling_mean(acc);

但是我想存储 accumulator_set在 map 中。我尝试编写这样的代码,但我卡住了:

map<int, accumulator_set<long, stats<tag::rolling_mean> > > avg;

void update(int id, long data){
    if(avg.count(id)==0){
        //key doesn't exist in map
        avg[id]= ;// How to create acc as in above example and store it in map?
    }
    accumulator_set<long, stats<tag::rolling_mean> > &acc = avg[id];
    acc(data);
}

void read(int id){
    cout << rolling_mean(avg[id]) ;
}

如何创建 accumulator_set如上面的示例所示并将其(引用或对象)存储在 map 中?

最佳答案

您可以使用 insert():

typedef accumulator_set<long, stats<tag::rolling_mean> > acc_set_t;

if(avg.count(id)==0){
    //key doesn't exist in map
    avg.insert( std::make_pair(id, acc_set_t(/*init parameters here*/) ));
}

关于c++ - 将 boostaccumulator_set 存储在 STL 映射中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10273888/

相关文章:

c++ - 链接项目 C++ Cygwin

c++ - 纯抽象类和派生类型的实例化

python - 如何通过组合两个列表中的项目来创建字典?

Python 3-如何将一个字典中的键与另一个字典进行比较,将它们的值相加,并将结果存储在第一个字典的值中?

http - 在类型转换中出现错误 "type ' List<Map<String, Object>>' is not a subtype of type ' String'

c++ - 从成员指针获取指向封闭实例的指针

C++:在没有事件异常的情况下终止调用(GCC)

c++ - 如何知道何时将新文件添加到 Windows 中的文件系统?

c++ - 如何在模板函数中为整数类型选择snprinf掩码?

c++ - 正确初始化多维 vector