title: Variadic templates with const references
body: <p>My project uses custom allocator that constructs objects the following way:</p>
  
  <pre><code>template &lt;typename T, typename... Args&gt;
  T* create(Args... args)
  {
      T* object = // request "bare" memory
      // call object constructor
      return new(reinterpret_cast&lt;void*&gt;(object)) T(args...);
  }
  </code></pre>
  
  <p>There is a class, containing const reference as a field:</p>
  
  <pre><code>struct A {
    A(const string&amp; s) : str_(s) {
      cout &lt;&lt; &amp;s &lt;&lt; '\n';
    }
  
    const string&amp; str_;
  };
  </code></pre>
  
  <p>But when I'm trying to create an object, I'm getting wrong results:</p>
  
  <pre><code>string* str = new string("some string");
  cout &lt;&lt; str &lt;&lt; '\n';
  A* a = create&lt;A&gt;(*str);
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>0x7fffc8004db4
  0x7fffd5436050
  </code></pre>
  
  <p>I thought the const reference field (<code>str_</code>) should contain the same address, that has been given to construction machinery, but obviously it isn't true.</p>
  
  <p>Why is it happen, and how to avoid it?</p>
  
  <p><em>Ofc, I can not help using custom allocators, it is mandatory, I wouldn't ask.</em></p>