title: Copying objects using different allocators in C++
body: <p>So I have a nice persistent allocator class <code>persistent_alloc&lt;T&gt;</code> that allows me to allocate C++ container objects and strings in persistent memory which is backed by an mmaped file that can persist from one run of my program to the next.</p>
  
  <p>My problem comes when I want to do anything that mixes persistent and non persistent objects.  For example, I have</p>
  
  <pre><code>typedef std::basic_string&lt;char, std::char_traits&lt;char&gt;, persistent_alloc&lt;char&gt;&gt; pstring;
  
  pstring a, b, c;
  std::string x, y, z;
  </code></pre>
  
  <p>I want to be able to do things like:</p>
  
  <pre><code>if (a == x)
      a = y;
  c = z + b;
  </code></pre>
  
  <p>and so forth, but by default it does not work, as <code>pstring</code> and <code>std::string</code> are unrelated types.  Now as far as the comparison is concerned, I can define:</p>
  
  <pre><code>template&lt;typename Alloc1, typename Alloc2&gt; inline bool
  operator==(const std::basic_string&lt;char, std::char_traits&lt;char&gt;, Alloc1&gt; &amp;a,
             const std::basic_string&lt;char, std::char_traits&lt;char&gt;, Alloc2&gt; &amp;b)
  {
      return strcmp(a.c_str(), b.c_str()) == 0;
  }
  </code></pre>
  
  <p>...and now I can compare strings for equality.  But adding these for every operation seems like a pain -- it seems like they SHOULD be provided by the standard library.  Worse, assignment operators and copy constructors must be members and can't be defined as global inline functions like this.</p>
  
  <p>Is there a reasonable way of doing this?  Or do I have to effectively rewrite the entire standard library to support allocators usefully?</p>