title: Which allocator does std::vector's copy constructor use to allocate memory?
body: <p>I have a custom allocator template <code>MyAllocator&lt;T&gt;</code>. I am attempting to create a class template that essentially boils down to the following:</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  class MyClass&lt;T&gt; {
      std::vector&lt;T, MyAllocator&lt;T&gt;&gt; &amp;data;
  public:
      MyClass(std::vector&lt;T, MyAllocator&lt;T&gt;&gt; &amp;data) : data(data) {}
      MyClass(std::vector&lt;T&gt; &amp;data) : data(data) {}
  }
  </code></pre>
  <p>My intention is to avoid copying <code>data</code> when its memory allocation was dictated by <code>MyAllocator&lt;T&gt;</code>. I know that this can be hairy in some contexts, but this class is a short-lived utility wrapper, and this is a performance-critical application.</p>
  <p>The part that confuses me, however, is the member initializer list of the second constructor. After looking closely at the documentation, I can't seem to explain why this operation is type-safe. It is my understanding that <code>data(data)</code> will look for the constructor <code>std::vector&lt;T, MyAllocator&lt;T&gt;&gt;::vector(std::vector&lt;T, std::allocator&lt;T&gt;&gt;)</code> (or a pass-by-reference variant). This constructor doesn't seem to exist, yet I have not encountered any compile-time type errors.</p>
  <p>At first I thought it was because the <code>data</code> member variable is a reference, but changing it to a value did not create any type errors. <code>MyAllocator</code> is not a subclass of <code>std::allocator</code>, so I don't see how an implicit cast could be responsible for this behavior either.</p>
  <p>What am I missing? And if this is indeed legal code, does the second constructor create a new memory allocation with <code>MyAllocator</code> like I'm hoping it does?</p>