title: Initializing std::array inside a function
body: <p>I want to create a function that resizes a stack. It will create a new array with a larger or smaller size depending on the value of max, then copy the elements into that new array.</p>
  
  <pre><code>void resize(const int&amp; max) {
      std::array&lt;Item, max&gt; temp;
      for (int i = 0; i &lt; n; i++) {
          temp.at(i) = a.at(i);
      }
      a = temp;
  }
  </code></pre>
  
  <p>I know this will not run because max is not a constant expression. I absolutely don't know how to pass a constant int value. I tried:</p>
  
  <p>void resize(constexpr int&amp; max) //compiler says cannot make int arg constexpr</p>
  
  <p>I don't want to do constexpr void resize because I don't need the function to be evaluated at compile time, and it didn't work anyway.</p>
  
  <p>Note: I know this might be easier if I used std::vector because it's resizable, but I want to try to experiment with std::array.</p>
  
  <p>What should I do?</p>