title: How to pass a constexpr as a function parameter c++
body: <p>I have a simple function that populates an array with double values and returns the array:</p>
  <pre><code>double create_step_vectors(int n_steps, double step_size)
  {
      std::array&lt;double, n_steps + 1&gt; vec{};
      for (int i = 0; i &lt;= n_steps; i++)
      {
          arr[i] = i * step_size;
      }
      return arr
  }
  </code></pre>
  <p>I pass in n_steps which is defined in main scope as:</p>
  <pre><code>    constexpr int n_step {static_cast&lt;int&gt;(1 / x_step) };
  </code></pre>
  <p>I get the error:</p>
  <pre><code>    error: 'n_steps' is not a constant expression
     13 |     std::array&lt;double, n_steps + 1&gt; vec{};
  </code></pre>
  <p>I have tried to put n_steps + 1 in curly brackets which didn't help. The purpose of n_steps, where the error occurs, is to set the size of the array, arr.</p>
  <p>How could I solve this issue?</p>