title: How to use static_assert for constexpr function arguments in C++?
body: <p>I have several brief <code>constexpr</code> functions in my libraries that perform some simple calculations. I use them both in run-time and compile-time contexts.</p>
  
  <p>I would like to perform some assertions in the body of these functions, however <code>assert(...)</code> is not valid in a <code>constexpr</code> function and <code>static_assert(...)</code> can not be used to check function parameters.</p>
  
  <p>Example:</p>
  
  <pre><code>constexpr int getClamped(int mValue, int mMin, int mMax) noexcept
  {
      assert(mMin &lt;= mMax); // does not compile!
      return mValue &lt; mMin ? mMin : (mValue &gt; mMax ? mMax : mValue);
  }
  </code></pre>
  
  <p>Is there a way to <em>check</em> whether the function is being executed in a run-time or compile-time constant and execute the <code>assert</code> only if it's being executed at run-time?</p>
  
  <pre><code>constexpr int getClamped(int mValue, int mMin, int mMax) noexcept
  {
      assert_if_runtime(mMin &lt;= mMax); 
      return mValue &lt; mMin ? mMin : (mValue &gt; mMax ? mMax : mValue);
  }
  </code></pre>