title: boost interprocess unordered_map string
body: <p>I am trying to create a unordered_map in shared memory using Boost Interprocess library. Here, is the code, which I'm trying to use (taking examples from Boost Interprocess documentation):</p>
  
  <pre><code>#include &lt;boost/interprocess/managed_shared_memory.hpp&gt;
  #include &lt;boost/interprocess/allocators/allocator.hpp&gt;
  #include &lt;functional&gt;
  #include &lt;boost/functional/hash.hpp&gt;
  #include &lt;boost/unordered_map.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;boost/interprocess/containers/string.hpp&gt;
  
  namespace bipc = boost::interprocess;
  
  typedef bipc::allocator&lt;char, bipc::managed_shared_memory::segment_manager&gt; CharAllocator;
  typedef bipc::basic_string&lt;char, std::char_traits&lt;char&gt;, CharAllocator&gt; ShmemString;
  
  
  struct Person
  {
    int age;
    ShmemString name;
    double salary;
  
    Person(int i,
       double sal,
       const char* s,
       const char_allocator&amp; a)
      : age(i),
        name(s, a),
        salary(sal)
      {
      }
    void print() {}
  }
  
  typedef ShmemString KeyType;
  typedef Person MappedType;
  
  typedef std::pair&lt; KeyType, MappedType &gt; MapPersonType;
  
  
  typedef bipc::allocator&lt; MapPersonType,
                       bipc::managed_shared_memory::segment_manager &gt;
  ShMemAllocator;
  
  typedef boost::unordered_map&lt; KeyType,
                            MappedType,
                            boost::hash&lt;KeyType&gt;,
                            std::equal_to&lt;KeyType&gt;,
                            ShMemAllocator &gt;
  PersonMap;
  </code></pre>
  
  <p>This is what I'm trying to do in the main program:</p>
  
  <pre><code>int main() 
  {
  bipc::managed_shared_memory segment(bipc::create_only, "MySharedMemory", 65536);
  
  PersonMap *persons = segment.construct&lt;PersonMap&gt;("MyHashMap")
      ( 3, boost::hash&lt;ShmemString&gt;(), std::equal_to&lt;ShmemString&gt;()
          , segment.get_allocator&lt;MapPersonType&gt;());
  
  char_allocator alloc(segment.get_allocator&lt;char&gt;());
  
  Person p1(20, 10000, "ABC", alloc);
  persons-&gt;insert(MapPersonType(ShmemString("Person1", alloc), p1));
  }
  </code></pre>
  
  <p>Using the above code, I'm able to create an unordered_map in shared memory. However, when I am trying to access the map, I need to use a syntax like</p>
  
  <pre><code>persons-&gt;at(ShmemString("H", segment.get_allocator&lt;char&gt;())).print();
  </code></pre>
  
  <p>However, I would prefer to do this with a std::string, which results in compilation errors:</p>
  
  <pre><code>persons-&gt;at(std::string("H")).print();
  </code></pre>
  
  <p>Is it possible to write the above statement, i.e.  accessing the map allocated in shared memory with std::string?</p>