title: Synonym function call for ::new((void*)p)T(value);
body: <p>I am trying to write my own <code>Allocator</code> which can be used in STL. That far I could almost successfully finish but with one function I have my problem:</p>
  
  <p>The <code>Allocator</code> used in STL should provide the function <code>construct</code> [example from a standard allocator using <code>new</code> &amp; <code>delete</code>]:</p>
  
  <pre><code>// initialize elements of allocated storage p with value value
  void construct (T* p, const T&amp; value)
  {
      ::new((void*)p)T(value);
  }
  </code></pre>
  
  <p>I am stuck how to rewrite this using my own function which replaces the <code>new</code> keyword initializing it with the <code>value</code>.</p>
  
  <p>This function <code>construct</code> is for example used in this code: <code>fileLines.push_back( fileLine );</code></p>
  
  <p>where</p>
  
  <pre><code>MyVector&lt;MyString&gt;      fileLines;
  MyString                fileLine;
  </code></pre>
  
  <p>These are my <code>typedefs</code> where I use my own <code>Allocator</code>:</p>
  
  <pre><code>template &lt;typename T&gt; using MyVector = std::vector&lt;T, Allocator&lt;T&gt;&gt;;
  using MyString = std::basic_string&lt;char, std::char_traits&lt;char&gt;, Allocator&lt;char&gt;&gt;;
  </code></pre>
  
  <p>I am confused because here is allocated a <code>pointer</code> to <code>T</code> which can be for example [when I understood it correctly]  <code>MySstring</code>.</p>
  
  <p>Do I understand it correctly that the pointer - allocated by <code>new</code> - will have 10 bytes, when <code>value</code> is <code>123456789</code> and then the provided <code>value</code> is copied to the new pointer?</p>
  
  <p><strong>My question:</strong></p>
  
  <p>How to rewrite the one line of code using my own function? For me the <em>difficult</em> point is how to get the length of <code>value</code> [which can have any type] in order I can correctly determinate the length of the allocated block and how to <em>copy</em> it in order it works for all possible types <code>T</code>?</p>