title: How to use std::allocator in my own container class
body: <p>I am trying to write a container class which uses STL allocators. What I currently do is to have a private member</p>
  
  <pre><code>std::allocator&lt;T&gt; alloc_;
  </code></pre>
  
  <p>(this will later be templated so that the user can pick a different allocator) and then call</p>
  
  <pre><code>T* ptr = alloc_.allocate(1,0);
  </code></pre>
  
  <p>to get a pointer to a newly allocated 'T' object (and used alloc_.construct to call the constructor; see the answer below). This works with the GNU C++ library.</p>
  
  <p>However, with STLPort on Solaris, this fails to do the right thing and leads to all sorts of bizarre memory corruption errors. If I instead do</p>
  
  <pre><code>std::allocator_interface&lt;std::allocator&lt;T&gt; &gt; alloc_;
  </code></pre>
  
  <p>then it is all working as it should.</p>
  
  <p>What is the correct way to use the stl::allocator? The STLPort/Solaris version fails to compile with g++, but is g++ right?</p>