title: Compile-time literal string as template argument
body: <p>I'm trying to convert a C++ literal string into an instance of the following template:</p>
  
  <pre><code>template &lt;char ... C&gt;
  struct string_literal {
      typedef string_constant type;
      static constexpr const char value[sizeof...(C)] = {C...};
      constexpr operator const char* (void) const {
          return value;
      }
  };
  template &lt;char ... C&gt;
  constexpr const char string_literal&lt;C...&gt;::value[sizeof...(C)];
  </code></pre>
  
  <p>I came up with these helpers based on various sources for 'unpacking' the quoted string value into the template above.</p>
  
  <pre><code>template &lt;unsigned N, const char (&amp;S) [N], typename U&gt;
  struct selector;
  
  template &lt;unsigned N, const char (&amp;S) [N], unsigned ...I&gt;
  struct selector&lt;N, S, index_sequence&lt;I...&gt;&gt; {
      using type = string_literal&lt;S[I]...&gt;;
  };
  
  template &lt;unsigned N, const char (&amp;S) [N]&gt;
  struct unpack {
      using type = typename selector&lt;N, S, make_index_sequence&lt;N&gt;&gt;::type;
  };
  </code></pre>
  
  <p>However, when a call this I get a compiler error:</p>
  
  <pre><code>template &lt;unsigned N&gt;
  constexpr auto make_string_literal(const char (&amp;s) [N]) {
      return unpack&lt;N, s&gt;{}; // Error here
  }
  
  constexpr auto literal = make_string_literal("test");
  // string_literal&lt;'t','e','s','t','\0'&gt;
  </code></pre>
  
  <p>GCC 4.9+ reports:
  <strong>error: 'const char (&amp; s)[1]' is not a valid template argument for type 'const char (&amp;)[1]' because a reference variable does not have a constant address</strong></p>
  
  <p>Clang 3.7.1 reports:
  <strong>error: non-type template argument refers to object 's' that does not have linkage</strong></p>
  
  <p>I tried a few different approaches but the errors are mostly the same.
  What am I missing here?</p>