Issues with boost::multi_index
Issues with boost::multi_index
当我尝试创建这个对象时,
typedef boost::multi_index_container<
ClassX*, //mapped value
boost::multi_index::indexed_by< //list of indices
boost::multi_index::hashed_unique<
boost::multi_index::const_mem_fun<ParentClassOfX, Key1, &ParentClassOfX::getKey1> //hashed index by unique Key1
>,
boost::multi_index::hashed_unique<
boost::multi_index::const_mem_fun<ParentClassOfX, Vs64, &ParentClassOfX::getKey2> //hashed index by unique Key1
>
>
>ClassXMultiKeyIndexed;
,
ClassXMultiKeyIndexed sample;
并插入一个指针,像这样,
ClassX *a;
ClassXMultiKeyIndexed sample;
//a is not NULL and is filled up before the below insert
sample.insert(a);
这是编译错误,如果"sample.insert(a)"被注释掉,它会编译得很好。
编译错误:Compiling...
.
.
.
xtyab.cpp
c:codecommonlibboostboostdetailallocator_utilities.hpp(153) : error C2061: syntax error : identifier 'p'
c:codecommonlibboostboostmulti_indexdetailindex_base.hpp(105) : see reference to function template instantiation 'void boost::detail::allocator::construct<Container*>(void *,const Type &)' being compiled
with
[
Type=Container *
]
c:codecommonlibboostboostmulti_indexdetailindex_base.hpp(102) : while compiling class template member function 'boost::multi_index::detail::hashed_index_node<Super,Category> *boost::multi_index::detail::index_base<Value,IndexSpecifierList,Allocator>::insert_(Container *const &,boost::multi_index::detail::hashed_index_node<Super,Category> *&,boost::multi_index::detail::lvalue_tag)'
with
[
Super=boost::multi_index::detail::hashed_index_node<boost::multi_index::detail::index_node_base<Container *,std::allocator<Container *>>,boost::multi_index::detail::hashed_unique_tag>,
Category=boost::multi_index::detail::hashed_unique_tag,
Value=Container *,
IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>,
Allocator=std::allocator<Container *>
]
c:codecommonlibboostboostmulti_indexhashed_index.hpp(93) : see reference to class template instantiation 'boost::multi_index::detail::index_base<Value,IndexSpecifierList,Allocator>' being compiled
with
[
Value=Container *,
IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>,
Allocator=std::allocator<Container *>
]
c:codecommonlibboostboostmulti_indexhashed_index.hpp(93) : see reference to class template instantiation 'boost::multi_index::detail::hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>' being compiled
with
[
KeyFromValue=boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>,
Hash=boost::hash<boost::long_long_type>,
Pred=std::equal_to<__int64>,
SuperMeta=boost::multi_index::detail::nth_layer<2,Container *,boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>,std::allocator<Container *>>,
TagList=boost::mpl::vector0<boost::mpl::na>,
Category=boost::multi_index::detail::hashed_unique_tag
]
c:codecommonlibboostboostmulti_index_container.hpp(100) : see reference to class template instantiation 'boost::multi_index::detail::hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>' being compiled
with
[
KeyFromValue=boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>,
Hash=boost::hash<boost::long_long_type>,
Pred=std::equal_to<__int64>,
SuperMeta=boost::multi_index::detail::nth_layer<1,Container *,boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>,std::allocator<Container *>>,
TagList=boost::mpl::vector0<boost::mpl::na>,
Category=boost::multi_index::detail::hashed_unique_tag
]
c:codecommonsrcbizmodelstm-stow_modelstm_container_manager_abc.h(323) : see reference to class template instantiation 'boost::multi_index::multi_index_container<Value,IndexSpecifierList>' being compiled
with
[
Value=Container *,
IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>
]
Build log was saved at "file://c:codewinDebugobjBuildLog.htm"
ProjABC - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
编译器指向boost谢谢!
错误信息c:codecommonlibboostboostdetailallocator_utilities.hpp(153) : error C2061: syntax error : identifier 'p'
暗示您修改了boost源,可能是无意的。
这对于boost多索引容器来说不太可能是一个问题,您没有给出太多细节,但是下面的代码是基于您的方法的,应该可以很好地编译。在你的编译器上尝试一下——一旦你向自己证明了,然后比较不同的地方并修复它。
#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
using boost::multi_index_container;
using boost::multi_index::indexed_by;
using boost::multi_index::hashed_unique;
using boost::multi_index::tag;
using namespace std;
struct foo {
int id_a;
int id_b;
int get_id_a() const {
return id_a;
}
int get_id_b() const {
return id_b;
}
};
struct tag_a {};
struct tag_b {};
using foo_container = boost::multi_index_container<
foo*,
indexed_by<
hashed_unique<tag<tag_a>, BOOST_MULTI_INDEX_CONST_MEM_FUN(foo, int, get_id_a)>,
hashed_unique<tag<tag_b>, BOOST_MULTI_INDEX_CONST_MEM_FUN(foo, int, get_id_b)>
>
>;
int main() {
foo_container c;
foo f1{1, 2};
foo f2{2, 3};
c.insert(&f1);
c.insert(&f2);
{
auto it = c.get<tag_a>().find(1);
if (it != c.get<tag_a>().end()) {
cout << (*it)->id_a << ' ' << (*it)->id_b << endl;
}
}
{
auto it = c.get<tag_b>().find(3);
if (it != c.get<tag_b>().end()) {
cout << (*it)->id_a << ' ' << (*it)->id_b << endl;
}
}
}
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- DrawIndexedInstanced 具有不同的 Index Count per Instance (Directx
- 有没有办法使用递归函数找到数组中最小值的 INDEX?C++
- 可视化C++:发布模式的运行时库作为'Multi-threaded Debug DLL'
- OpenGL VBO Indexing ( How to compute Index Array)
- "Warning: Comma within array index expression"但逗号分隔函数参数
- 如何根据排序索引的向量对 std::index 集进行排序?
- 在一行代码中理解 index++
- 为什么打印 c 样式字符串的'address of index n'会导致子字符串的输出
- boost beast Websocket Multi Request Server/Client 并不是真正的 mul
- 使用 std::get 访问 std::variant<index>
- 代码中的"vector<<int>vector>&index"是什么意思?
- c++如何使用Curl Multi-Interface连续循环
- CStringArray::GetAt(int index) 返回一个 const. 为什么?
- 如何配置 Doxygen 以在"Class Index"中包含类的类型定义?
- 在 R 中调用"multi file C++ code with external libraries referenced"
- 如何使用 std::get 作为 boost-multi-index 容器键的global_fun
- Boost Multi Index标识索引
- Boost Multi Index:基于列表内容的索引
- Boost Multi-Index中的多个索引查询