title: template C++ array
body: <p>I wish to define a type String such that declaring a variable of type String is at compile-time equivalent to char[N].  I have seen examples of template functions of certain array dimension but none to work on actual concrete types themselves.</p>
  
  <pre><code>namespace myns {
  
     typedef uint32_t LongCount;
     typedef uint16_t ShortCount;
  
     typedef uint32_t LongDist;
     typedef uint16_t ShortDist;
  
     #define LONG_NAME 20;
     #define SHORT_NAME 10;
  
     // this would be better in my opinion:
     typedef String&lt;20&gt; LongName;
     typedef String&lt;10&gt; ShortName;
  
  
  template&lt;typename DIST1, typename DIST2, typename COUNT1&gt;
  struct SomeStruct1Base
  {
     DIST1 dist1;
     DIST2 dist2;
     COUNT1 c;
  };
  
  typedef SomeStruct1Base&lt;LongDist, LongDist, LongCount&gt; SomeStruct1Long;
  typedef SomeStruct1Base&lt;ShortDist, ShortDist, ShortCount&gt; SomeStruct1Short;
  
  template&lt;typename DIST1, typename COUNT1, int NAME_LEN&gt;
  struct SomeStruct2Base
  {
     DIST1 dist1;
     uint32_t distx;
     COUNT1 c;
     char   name[NAME_LEN];
  };
  
  typedef SomeStruct2Base&lt;LongDist, LongCount, SHORT_NAME&gt; SomeStruct2Long;
  typedef SomeStruct2Base&lt;LongDist, LongCount, SHORT_NAME&gt; SomeStruct2Short;
  typedef SomeStruct2Base&lt;LongDist, LongCount, LONG_NAME&gt; SomeStruct2Ext;
  </code></pre>
  
  <p>The above is not very consistent and I think it would be better to pass in String&lt;6> or whatever instead of passing in an int parameter to the template.  No?</p>
  
  <p>Update: I am using this structure to parse network data represented in char buffers so the struct needs to be able to do reinterpret_cast&lt;>able.  Sorry I didn't mention this earlier but I'm mentioning it now as I see some of the suggestions will break under the circumstance.</p>