title: Internal typedefs in C++ - good style or bad style?
body: <p>Something I have found myself doing often lately is declaring typedefs relevant to a particular class inside that class, i.e.</p>
  
  <pre><code>class Lorem
  {
      typedef boost::shared_ptr&lt;Lorem&gt; ptr;
      typedef std::vector&lt;Lorem::ptr&gt;  vector;
  
  //
  // ...
  //
  };
  </code></pre>
  
  <p>These types are then used elsewhere in the code:</p>
  
  <pre><code>Lorem::vector lorems;
  Lorem::ptr    lorem( new Lorem() );
  
  lorems.push_back( lorem );
  </code></pre>
  
  <p>Reasons I like it:</p>
  
  <ul>
  <li>It reduces the noise introduced by the class templates, <code>std::vector&lt;Lorem&gt;</code> becomes <code>Lorem::vector</code>, etc.</li>
  <li>It serves as a statement of intent - in the example above, the Lorem class is intended to be reference counted via <code>boost::shared_ptr</code> and stored in a vector.</li>
  <li>It allows the implementation to change - i.e. if Lorem needed to be changed to be intrusively reference counted (via <code>boost::intrusive_ptr</code>) at a later stage then this would have minimal impact to the code.</li>
  <li>I think it looks 'prettier' and is arguably easier to read.</li>
  </ul>
  
  <p>Reasons I don't like it:</p>
  
  <ul>
  <li>There are sometimes issues with dependencies - if you want to embed, say, a <code>Lorem::vector</code> within another class but only need (or want) to forward declare Lorem (as opposed to introducing a dependency on its header file) then you end up having to use the explicit types (e.g. <code>boost::shared_ptr&lt;Lorem&gt;</code> rather than <code>Lorem::ptr</code>), which is a little inconsistent.</li>
  <li>It may not be very common, and hence harder to understand?</li>
  </ul>
  
  <p>I try to be objective with my coding style, so it would be good to get some other opinions on it so I can dissect my thinking a little bit.</p>