这是我用来测试的代码:
这是我用来测试的代码:
#include <iostream>
#include <boost/interprocess/managed_mapped_file.hpp>
#include <boost/container/map.hpp>
#include <boost/interprocess/managed_external_buffer.hpp>
#include <boost/interprocess/allocators/node_allocator.hpp>
#include <boost/container/vector.hpp>
namespace bi = boost::interprocess;
int main() {
bi::managed_mapped_file mmfile(bi::open_or_create, "map_iv.dat", 10000000);
typedef bi::allocator<int, bi::managed_mapped_file::segment_manager> int_allocator;
typedef boost::container::vector<int, int_allocator> MyVec;
typedef std::pair<const std::string, MyVec> MyPair;
typedef std::less<std::string> MyLess;
typedef bi::node_allocator<MyPair, bi::managed_mapped_file::segment_manager> node_allocator_t;
typedef boost::container::map<std::string, MyVec, std::less<std::string>, node_allocator_t> MyMap;
MyMap * mapptr = mmfile.find_or_construct<MyMap>("mymap")(mmfile.get_segment_manager());
(*mapptr)["Hello"].push_back(17);
long long s = mapptr->size();
std::cout << s << ' ';
std::cout << (*mapptr)["World"][0] << ' ';
return 0;
}
我在Visual Studio 2017中遇到了如下错误信息:
boost_1_69_0\boost\container\vector.hpp(294): error C2512:
"boost::interprocess::allocator<int,boost::interprocess::segment_manager<CharType,MemoryAlgorithm,IndexType>>::allocator": no appropriate default constructor available
我正在努力让它运行起来,非常感谢任何帮助!