【发布时间】:2015-06-05 09:58:17
【问题描述】:
我想对缓存中的某些静态函数使用 const 缓存的性能进行基准测试。所以我有类似的东西:
class Foo {
static double cost(int factor) { <moderately complex function> };
// Other stuff using the cost() function
};
并且我想与像这样的替代版本进行基准测试:
class Foo {
private:
static double _cost(int factor) { <same function as before> };
static const double cost_cache[MAX_FACTOR] = ???;
public:
static double cost(int factor) { return cost_cache[factor]; };
// Other stuff
}
通过一种方式来初始化我的 cost_cache 数组,相当于
for (int idx = 0; i < MAX_FACTOR; ++i)
cost_cache[idx] = _cost(idx);
在高级函数式语言中,我会使用地图原语。如何在 C++11(或 C++14?)中正确初始化它在源代码中。
我正在使用clang++
【问题讨论】: