title: C++ Template specialisation - illegal type for non-type template parameter '__formal
body: <p>I need to parse a custom protocol's frames that can contain intergers of various sizes (uint8_t, uint16_t, uint32_t, etc...) and strings of chars prefixed by their length (uint16_t).</p>
  
  <p>I want to write a template function to read such values from a vector of bytes to make the syntax more readable. Here are my functions :</p>
  
  <pre><code>template&lt; typename type &gt;
  type read( const std::vector&lt; byte &gt; &amp; bytes, uint index )
  {
      if( index + sizeof( type ) &gt; bytes.size() )
      {
          throw exception( "read() - Out of range." );
      }
  
      type val;
      memcpy( &amp; val, &amp; bytes[ index ], sizeof( type ) );
  
      return val;
  }
  
  template&lt; std::string &gt;
  std::string read( const std::vector&lt; byte &gt; &amp; bytes, uint index ) // ERROR HERE
  {
      if( index + sizeof( type ) &gt; bytes.size() )
      {
          throw exception( "read() - Out of range." );
      }
  
      uint16_t length = read&lt; uint16_t &gt;( bytes, 0 );
  
      std::string str( length, '\0' );
  
      for( uint16_t i = 0; i &lt; length; ++i )
      {
          str[i] = read&lt; char &gt;( bytes, index + i );
      }
  
      return str;
  }
  </code></pre>
  
  <p>I'm getting this error on VS2005 :</p>
  
  <pre><code>Error   1   error C2993: 'std::string' : illegal type for non-type template parameter '__formal'    c:\dev\floatinglicences\common\common.h 50
  </code></pre>
  
  <p>I'm not an expert with templates. It's the first time i need trying to do a template specialisation, so my syntax might be wrong.</p>
  
  <p>Will you help me ? Thank you :)</p>