Boost累加器有一个不幸的怪癖,当在类内部使用时,api接口的行为会有所不同。
我试图在类中使用Boost累加器quantile_probability,但是我想不出如何使它工作。
这个问题类似于这个问题:Can boost accumulators be used as class members
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp>
#include <boost/accumulators/statistics/weighted_p_square_quantile.hpp>
#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
namespace ba = boost::accumulators;
typedef ba::accumulator_set<int64_t, ba::stats<ba::tag::weighted_p_square_quantile>, int64_t> accumulator_t;
struct Foo {
accumulator_t myAcc(ba::quantile_probability = 0.90); // Doesn't work. ERROR: ‘ba::quantile_probability’ is not a type
};
accumulator_t acc(ba::quantile_probability = 0.90); // I just fine!发布于 2022-09-16 00:03:20
accumulator_t myAcc(中的方括号被解析为成员函数,在这种情况下,这是定义一个变量为ba::qunatile_probability的函数。但那不是一种类型,所以它失败了。
您需要用=或{编写初始化程序,或者将其写入构造函数的初始化程序列表中。
struct Foo {
// One of these
accumulator_t myAcc = accumulator_t(ba::quantile_probability = 0.90);
accumulator_t myAcc{ba::quantile_probability = 0.90};
accumulator_t myAcc;
Foo() : myAcc(ba::quantile_probability = 0.90) {}
};https://stackoverflow.com/questions/73737420
复制相似问题