Initializing a static class member array with a non-trivial expression in C++11 <p>I would like to benchmark the performance of using a const cache for some static function inside a cache. So I have something like that:</p> <pre><code>class Foo { static double cost(int factor) { &lt;moderately complex function&gt; }; // Other stuff using the cost() function }; </code></pre> <p>And I would like to benchmark against an alternative version like this one:</p> <pre><code>class Foo { private: static double _cost(int factor) { &lt;same function as before&gt; }; static const double cost_cache[MAX_FACTOR] = ???; public: static double cost(int factor) { return cost_cache[factor]; }; // Other stuff } </code></pre> <p>With a way to initialize my cost_cache array in a way equivalent to</p> <pre><code>for (int idx = 0; i &lt; MAX_FACTOR; ++i) cost_cache[idx] = _cost(idx); </code></pre> <p>In a high-level functional language I would use a map primitive. How do I properly initialize that in C++11 (or C++14 ?) I saw other posts addressing similar questions, like <a href="http://stackoverflow.com/questions/27569249/">Initializing private member static const array</a>, but its solution is inapplicable in my case, I can't put the 10k values verbatim in source.</p> <p>I'm using <code>clang++</code></p>