Boost logo

Boost Users :

Subject: [Boost-users] Using subscript operator with interprocess map
From: Michi Mutsuzaki (michi_at_[hidden])
Date: 2010-09-07 20:30:01


El 03/09/2010 9:18, Michi Mutsuzaki escribió: > char_string needs an allocator in its constructor (not tested code): > (*mymap)[char_string("key", alloc_inst)] = 1; Thanks Ion, that fixed the compilation error. Now I'm trying create a map from char_string to char_string, and that's failing. Here is the code and the error message I'm getting (I'm really sorry I keep posting about compilation errors, but I'm having hard time parsing the error message): #include <functional> #include <iostream> #include <algorithm> #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, char_string> ValueType; typedef bi::allocator<ValueType, bi::managed_mapped_file::segment_manager> map_alloc; typedef bi::map<char_string, char_string, 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()); char_alloc alloc_inst2 (segment.get_segment_manager()); MyMap *mymap = segment.find_or_construct<MyMap>("MyMap") (std::less<char_string>(), alloc_inst); (*mymap)[char_string("key", alloc_inst2)] = char_string("val", alloc_inst2); return 0; } /usr/local/include/boost/interprocess/containers/map.hpp: In instantiation of `T& boost::interprocess::map<Key, T, Pred, Alloc>::operator[](const typename boost::interprocess::detail::rbtree<Key, std::pair<const Key, T>, boost::interprocess::detail::select1st<std::pair<const Key, T> >, Pred, Alloc>::key_type&) [with Key = char_string, T = char_string, Pred = std::less<char_string>, Alloc = map_alloc]': boost_test.cc:27: instantiated from here /usr/local/include/boost/interprocess/containers/map.hpp:325: error: no matching function for call to `boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0u>, boost::interprocess::iset_index> >::allocator()' /usr/local/include/boost/interprocess/allocators/allocator.hpp:135: note: candidates are: boost::interprocess::allocator<T, SegmentManager>::allocator(const boost::interprocess::allocator<T, SegmentManager>&) [with T = char, SegmentManager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0u>, boost::interprocess::iset_index>] /usr/local/include/boost/interprocess/allocators/allocator.hpp:130: note: boost::interprocess::allocator<T, SegmentManager>::allocator(SegmentManager*) [with T = char, SegmentManager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0u>, boost::interprocess::iset_index>]


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