从accumulator_set中删除或修改accumulators::tag

问题描述 投票:0回答:2

在 boost 中,是否可以从

boost::accumulators::tag
动态删除给定的
accumulator_set

typedef boost::accumulators::features <
    boost::accumulators::tag::count,
    boost::accumulators::tag::max,
    boost::accumulators::tag::min,
    boost::accumulators::tag::mean,
    boost::accumulators::tag::variance,
    boost::accumulators::tag::skewness,
    boost::accumulators::tag::kurtosis,
> StatisticalFeatures;
accumulator_set<double, boost::accumulators::stats<StatisticalFeatures>> acc;

或者,将一个新的

boost::accumulators::stats
容器分配给
accumulator_set
,我可以在其中从字符串中指定一些
boost::accumulators::tag
。例如,如果字符串是
min,max,mean
,那么我想创建一个新的
accumulator_set<double,bost::accumulators::stats<boost::accumulators::tag::min,boost::accumulators::tag::max,boost::accumulators::tag::mean>> acc

提前感谢您的建议。

c++ boost accumulator
2个回答
0
投票

简短回答:不。

更长的答案:通过类型擦除和大量模板元编程,一切皆有可能。

如果您觉得确实需要这个,请开始使用例如 .Boost Function 或 Boost Erasure,或者发布一个包含更详细目标和您遇到困难的地方的问题。有太多方法可以解释“将新的 boost::accumulators::stats 容器分配给accumulator_set,我可以从字符串中指定一些 boost::accumulators::tag”。

如果组合有限,Boost Variant 是您的朋友。否则,Boost Any 和...许多特殊情况来提取结果。不过,这将是/很多/元编程

实际上,如果你能负担得起,为什么不使用“maxfeatured”累加器集,并且根据文本配置只公开一次呢?您在运行时会做比需要的更多的工作,但您会在开发方面节省大量精力。


0
投票

标签无法删除,但可以将其指定为可删除:

typedef boost::accumulators::features <
    boost::accumulators::droppable<boost::accumulators::tag::count>,
    boost::accumulators::droppable<boost::accumulators::tag::max>,
    boost::accumulators::droppable<boost::accumulators::tag::min>,
    boost::accumulators::droppable<boost::accumulators::tag::mean>,
    boost::accumulators::droppable<boost::accumulators::tag::variance>,
    boost::accumulators::droppable<boost::accumulators::tag::skewness>,
    boost::accumulators::droppable<boost::accumulators::tag::kurtosis>,
> StatisticalFeatures;
accumulator_set<double, boost::accumulators::stats<StatisticalFeatures>> acc;

然后,您可以动态地删除不需要的标签,这样它们就不会被计算,例如:

acc.drop<boost::accumulators::tag::skewness>();
acc.drop<boost::accumulators::tag::kurtosis>();
© www.soinside.com 2019 - 2024. All rights reserved.