title: How can I pass a state to the rebind_alloc constructor in STL?
body: <p>Suppose I have a custom stateful allocator that I want to use for a STL container. The container is going to use the <code>rebind_alloc</code> trait to allocate its internal elements, thus by default (or by defining <code>rebind&lt;T&gt;::other</code>), I can ask it to use my allocator class for the internals as well.</p>
  <p>However, I would like to pass the state of my allocator.</p>
  <p>This related <a href="https://stackoverflow.com/q/4062503/5133167">question</a> asks why</p>
  <pre class="lang-cpp prettyprint-override"><code>  template&lt;class U&gt; allocator( const allocator&lt;U&gt; &amp; o ) throw()
  </code></pre>
  <p>exists and the answer suggests that what I want to do is possible.</p>
  <p>However, from my experiments (basically tracing calls to <code>Allocator()</code> and <code>template &lt;class U&gt; Allocator(const Allocator&lt;U&gt; &amp;other)</code> in a custom allocator), I couldn't get the <code>rebind_alloc</code> conversion constructor to be called instead of the default constructor.</p>