提高依赖模板结构的多指数容器模板类 [英] boost multi index container of template-dependent struct in template-class
问题描述
我想在一个类中的多指标容器,依赖于在类模板依赖级。
听起来很复杂,这里是code:
I want a multi-index-container in a class, that depends on a template-dependent class in the class. Sounds complicated, here is the code:
#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 ::开始()
函数这个code编译,但与 myDataContainer ::开始()
我收到以下错误:
Without the myDataContainer::begin()
function this code compiles, but with the myDataContainer::begin()
I get the following error:
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
我缺少的东西吗?这是提升一个bug或者是不可能的?`
Am I missing something? Is this a bug in boost or is it not possible?`
在此先感谢
VEIO
Thanks in advance veio
推荐答案
由于dataContainer是模板参数依赖,需要
Because dataContainer is template parameter dependent, you need
ordered_view& ordView = dataContainer.template get<TagOrdered>();
在的main()
你使用特定的专业化,所以有没有相关的前pressions了。
In main()
you use specific a specialization, so there are no dependent expressions any more.
这篇关于提高依赖模板结构的多指数容器模板类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!