Boost logo

Boost Users :

Subject: [Boost-users] Using subscript operator with interprocess map
From: Michi Mutsuzaki (michi_at_[hidden])
Date: 2010-09-03 03:18:26


Hello,

I'm using a map from basic_string to int on managed_mapped_file (boost 1.35.0).
Everything works except that I get a compilation error if I use subscript
operator. I'm trying something like this:

#include <boost/interprocess/managed_mapped_file.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/allocators/allocator.hpp>

namespace bi = boost::interprocess;

typedef bi::allocator<char, bi::managed_mapped_file::segment_manager>
        char_alloc;
typedef bi::basic_string<char, std::char_traits<char>, char_alloc>
        char_string;
typedef std::pair<const char_string, int> ValueType;
typedef bi::allocator<ValueType, bi::managed_mapped_file::segment_manager>
        map_alloc;
typedef bi::map<char_string, int, std::less<char_string>, map_alloc>
        MyMap;

int main ()
{
  bi::managed_mapped_file segment(bi::open_or_create, "/tmp/test", 65536);
  map_alloc alloc_inst (segment.get_segment_manager());
  MyMap *mymap = segment.find_or_construct<MyMap>("MyMap")
                 (std::less<bi::string>(), alloc_inst);
  (*mymap)[char_string("key")] = 1;
  return 0;
}

What am I doing wrong?

Thanks!
--Michi


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net