title: C++ : struggle with generic const pointer
body: <p>I've run into some annoying issues with const-correctness in some templated code, that ultimately boils down to the following observation: for some reason, given an STL-ish Container type T, <code>const typename T::pointer</code> does not actually seem to yeild a constant pointer type, even if <code>T::pointer</code> is equivalent to <code>T::value_type*</code>.</p>
  
  <p>The following example illustrates the problem.  Suppose you have a templated function that takes a Container which must meet the STL Random Access Container concept requirements.</p>
  
  <pre><code>template &lt;class Container&gt;
  void example(Container&amp; c)
  {
      const typename Container::pointer p1 = &amp;c[0]; // Error if c is const
      const typename Container::value_type* p2 = &amp;c[0]; 
  }
  </code></pre>
  
  <p>Then, if we pass this function a const container...</p>
  
  <pre><code>const std::vector&lt;int&gt; vec(10);
  example(vec);
  </code></pre>
  
  <p>...we get an invalid conversion from <code>const int*</code> to <code>int*</code>.  But why is <code>const typename Container::pointer</code> not the same as <code>const int*</code> in this example?</p>
  
  <p>Note that if I change <code>const typename Container::pointer</code> to simply <code>typename Container::const_pointer</code> it compiles fine, however, as far as I can tell, the const_pointer typedef is an extension, (I don't see it mentioned in the C++ standard Container Requirements (23.5, Table 65)), and so therefore I don't want to use it.  </p>
  
  <p>So how can I obtain a generic, const-correct pointer type from a container T? (I really can't see how to do this without using boost::mpl::if_ along with type_traits to check if the container is constant...but there must be a less verbose way to do this)</p>
  
  <p>Edit: In case it matters, I'm using gcc 4.3.2 to compile this.</p>