我正在使用 boost flat_map 并尝试对其进行迭代,但是,我无法弄清楚如何创建迭代器。
my_map = mySeg.find<tlsSHMMap>("temp_map").first; //fetch a pointer to the map
tlsShmemAllocator alloc_inst (mySeg.get_segment_manager());
for (boost::container::flat_map<int, tlsStorage, std::less<int>() ,alloc_inst >::const_iterator row = my_map->begin();
row != my_map->end();
++row)
{
//do stuff
}
'tlsStorage' 是我用来存储数据库数据的结构。boost flat map 在代码的其他地方声明如下:
boost::container::flat_map tls_temp_map = mySeg.construct<tlsSHMMap>("temp_map") (std::less<int>() ,alloc_inst); //object name
我上面的代码不起作用。这是错误,有什么想法吗?
src/dbm/dbm_shm_server.cc: In member function 'int redcom::dbm::ShmServer::StartServer()':
src/dbm/dbm_shm_server.cc:353:24: warning: unused variable 'tls_main_map' [-Wunused-variable]
tlsSHMMap* tls_main_map;
^
src/dbm/dbm_shm_server.cc:354:24: warning: unused variable 'tls_temp_map' [-Wunused-variable]
tlsSHMMap* tls_temp_map;
^
src/dbm/dbm_shm_server.cc: In member function 'void redcom::dbm::ShmServer::fake_notify()':
src/dbm/dbm_shm_server.cc:2023:84: error: the value of 'alloc_inst' is not usable in a constant expression
for (boost::container::flat_map<int, tlsStorage, std::less<int>() ,alloc_inst >::const_iterator row = my_map->begin();
^
src/dbm/dbm_shm_server.cc:2021:40: note: 'alloc_inst' was not declared 'constexpr'
const tlsShmemAllocator alloc_inst (mySeg.get_segment_manager());
^
src/dbm/dbm_shm_server.cc:2023:95: error: type/value mismatch at argument 4 in template parameter list for 'template<class Key, class T, class Compare, class Allocator> class boost::container::flat_map'
for (boost::container::flat_map<int, tlsStorage, std::less<int>() ,alloc_inst >::const_iterator row = my_map->begin();
^
src/dbm/dbm_shm_server.cc:2023:95: error: expected a type, got 'alloc_inst'
src/dbm/dbm_shm_server.cc:2023:113: error: invalid type in declaration before 'row'
for (boost::container::flat_map<int, tlsStorage, std::less<int>() ,alloc_inst >::const_iterator row = my_map->begin();
^
src/dbm/dbm_shm_server.cc:2023:113: error: expected ';' before 'row'
src/dbm/dbm_shm_server.cc:2023:113: error: 'row' was not declared in this scope
src/dbm/dbm_shm_server.cc:2024:37: error: expected ')' before ';' token
row != my_map->end();
^
src/dbm/dbm_shm_server.cc:2023:98: warning: unused variable 'const_iterator' [-Wunused-variable]
for (boost::container::flat_map<int, tlsStorage, std::less<int>() ,alloc_inst >::const_iterator row = my_map->begin();
^
src/dbm/dbm_shm_server.cc:2025:19: error: 'row' was not declared in this scope
++row)
^
src/dbm/dbm_shm_server.cc:2025:22: error: expected ';' before ')' token
++row)
^
distcc[31606] ERROR: compile src/dbm/dbm_shm_server.cc on localhost failed
scons: *** [debug/build/x86_64-unknown-freebsd9.2/dbm/dbm_shm_server.o] Error 1
scons: building terminated because of errors.