title: How do I convert a C string to a int at compile time?
body: <p>I want to be able to pass an integer or a double (or a string) as a template argument <em>and</em> in some instances convert the result to an integer and use it as a template argument for a type in the class.</p>
  
  <p>Here's what I've tried:</p>
  
  <pre><code>template &lt;typename MPLString&gt;
  class A
  {
      // the following works fine
      int fun()
      {
        // this function should return the int in the boost mpl type passed to it
        // (e.g. it might be of the form "123")
        return std::stoi(boost::mpl::c_str&lt;MPLString&gt;::value);
      }
  
      // the following breaks because std::stoi is not constexpr
      std::array&lt;int, std::stoi(boost::mpl::c_str&lt;MPLString&gt;::value)&gt; arr;
  };
  </code></pre>
  
  <p>Can I do this somehow? I've tried <code>std::stoi</code> and <code>atoi</code> but neither are <code>constexpr</code>... Any ideas how this could be done (I <em>cannot</em> change the template parameter to take an <code>int</code> directly, as it might be a double).</p>