提升模板类中模板相关结构的多索引容器
boost multi index container of template-dependent struct in template-class
我想要一个类中的多索引容器,这取决于类中依赖于模板的类。听起来很复杂,这是代码:
#include <boost/unordered_map.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
template <typename Type>
class myDataContainer{
public:
struct DataStruct{
double t;
std::vector<Type> data;
};
// indices structs
struct TagTime{};
struct TagOrdered{};
typedef boost::multi_index::multi_index_container<
DataStruct,
boost::multi_index::indexed_by<
boost::multi_index::hashed_unique<boost::multi_index::tag<TagTime>, boost::multi_index::member<DataStruct, double, &DataStruct::t> >,
boost::multi_index::ordered_unique<boost::multi_index::tag<TagOrdered>, boost::multi_index::member<DataStruct, double, &DataStruct::t> > // this index represents timestamp incremental order
>
> InnerDataContainer;
typedef typename boost::multi_index::index<InnerDataContainer,TagTime>::type timestamp_view;
typedef typename boost::multi_index::index<InnerDataContainer,TagOrdered>::type ordered_view;
InnerDataContainer dataContainer;
void begin(){
ordered_view& ordView = dataContainer.get<TagOrdered>();
ordView.begin();
}
};
int main(int argc, char *argv[])
{
myDataContainer<float> data;
myDataContainer<float>::ordered_view& ordView = data.dataContainer.get<TagOrder>();
ordView.begin();
}
如果没有myDataContainer::begin()
函数,这段代码可以编译,但是使用myDataContainer::begin()
,我得到以下错误:
main.cpp: In member function 'void myDataContainer<Type>::begin()':
main.cpp:134:66: error: expected primary-expression before '>' token
main.cpp:134:68: error: expected primary-expression before ')' token
我错过了什么吗?这是提升中的错误还是不可能?
提前致谢维奥
因为 dataContainer 依赖于模板参数,所以你需要
ordered_view& ordView = dataContainer.template get<TagOrdered>();
main()
,您使用特定的专用化,因此不再有依赖表达式。
相关文章:
- 保持排序的数据结构,允许log N插入时间,并且可以返回我在log N中查找的元素的索引
- 获取结构 c++ 中元素的索引
- C++ STL 数据结构常时按索引推送/弹出/随机访问,并具有指向元素的可靠指针
- 如何使用值获取结构的索引
- 如何二进制搜索结构向量并在适当的索引处插入
- 用于存储网格(将具有负索引)的数据结构
- 是否可以将结构分配给向量的索引?
- 在 c++ 中为结构实现索引器
- 查找索引数据结构,例如`sTD :: vector`(非数组)
- 如何对同一数组索引下的结构成员进行排序?
- 从右到左计算当前索引中的数据结构中的元素数,并打印每个元素的计数
- 使用c中的结构的malloc通过大量存储器进行索引
- 尝试将文件读入结构数组,但 for 循环仅显示第一个索引,其余索引显示为零
- 如何创建辅助数据结构来跟踪 c++ 中 decrease_key 操作的堆索引
- C 用于向量中的结构访问索引或使用参考值
- 如何使用索引访问C 结构属性值
- C++ 中结构的动态索引数组
- 当结构数组在主线程中填充数据时,从结构数组的低索引元素读取是否线程安全
- 如何取消结构的索引
- 索引结构是否合法?