title: C++ string.length() not usable in a constant expression
body: <p>Using c++. I have the following piece of code where I am trying to use template to pass the 
  size of a 2d array to the function foo. However the issue is that the size passed to the template has to be constant. Any pointers are helpful, thanks.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  template &lt;size_t r, size_t c&gt;
  bool foo(bool (&amp;arr)[r][c])
  {
      cout &lt;&lt; "foo\n";
  }
  
  int main() {
      string s = "abcd";
      const size_t N = s.length(); //is this incorrect?
      bool arr[N][N];
      foo&lt;N, N&gt;(arr);
      return 0;
  }
  </code></pre>
  
  <p>It seems that string.length() or string.size() cannot be used to initialize a constant. When I try to compile I get the error:</p>
  
  <pre><code>main.cpp: In function ‘int main()’:
  main.cpp:14:6: error: the value of ‘N’ is not usable in a constant expression
    foo&lt;N, N&gt;(arr);
        ^
  main.cpp:12:15: note: ‘N’ was not initialized with a constant expression
    const size_t N = s.length();
                 ^
  main.cpp:14:9: error: the value of ‘N’ is not usable in a constant expression
    foo&lt;N, N&gt;(arr);
           ^
  main.cpp:12:15: note: ‘N’ was not initialized with a constant expression
    const size_t N = s.length();
                 ^
  main.cpp:14:15: error: no matching function for call to ‘foo&lt;N, N&gt;(bool [N][N])’
    foo&lt;N, N&gt;(arr);
                 ^
  main.cpp:5:6: note: candidate: template&lt;long unsigned int r, long unsigned int c&gt; bool foo(bool (&amp;)[r][c])
   bool foo(bool (&amp;arr)[r][c])
        ^~~
  main.cpp:5:6: note:   template argument deduction/substitution failed:
  main.cpp:14:15: error: the value of ‘N’ is not usable in a constant expression
    foo&lt;N, N&gt;(arr);
                 ^
  main.cpp:12:15: note: ‘N’ was not initialized with a constant expression
    const size_t N = s.length();
                 ^
  main.cpp:14:15: note: in template argument for type ‘long unsigned int’ 
    foo&lt;N, N&gt;(arr);
                 ^
  main.cpp:14:15: error: the value of ‘N’ is not usable in a constant expression
  main.cpp:12:15: note: ‘N’ was not initialized with a constant expression
    const size_t N = s.length();
                 ^
  main.cpp:14:15: note: in template argument for type ‘long unsigned int’ 
    foo&lt;N, N&gt;(arr);
             ^
  </code></pre>