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
#include
#include
#include
namespace bi = boost::interprocess;
typedef bi::allocator
char_alloc;
typedef bi::basic_string
char_string;
typedef std::pair ValueType;
typedef bi::allocator
map_alloc;
typedef bi::map, 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(), 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::operator[](const typename
boost::interprocess::detail::rbtree,
boost::interprocess::detail::select1st >, Pred,
Alloc>::key_type&) [with Key = char_string, T = char_string, Pred =
std::less, 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, boost::interprocess::iset_index>
::allocator()'
/usr/local/include/boost/interprocess/allocators/allocator.hpp:135: note:
candidates are: boost::interprocess::allocator::allocator(const boost::interprocess::allocator&) [with T = char, SegmentManager =
boost::interprocess::segment_manager, boost::interprocess::iset_index>]
/usr/local/include/boost/interprocess/allocators/allocator.hpp:130:
note: boost::interprocess::allocator::allocator(SegmentManager*) [with T = char, SegmentManager =
boost::interprocess::segment_manager, boost::interprocess::iset_index>]