我有大意如下的一类通用转换迭代:定义为遍历不同的容器类型
class ArraySim{
public:
DataStructure* ds;
ArraySim(bool which){
if(true)
ds = new STDMap();
else
ds = new HashMap();
}
value_type& operator[](int idx){
return ds->getValAtIndex(idx);
}
//define a custom iterator type that can be used to iterate over both std::map and boost::unordered //map keys.
}
class DataStructure{
vitrual value_type& getValAtIndex(int idx)=0;
};
class STDMap: public DataStructure{
//Class that wraps a std::map object and implements the virtual method to return the value against a //particular index(key)
};
class HashMap: publlic DataStructure{
//Class that wraps a boost::unordered_map object and implements the virtual method to return the value //against a particular index(key)
}
我已通过:Generic Iterator和Transform Iterator。据我所知,转换迭代器仍然要求您在模板参数中提供底层容器迭代器。那么是否有一种方法可以使用变换迭代器来定义映射键周围的自定义迭代器类型,并同时使其适用于不同类型的映射容器?
可以删除的类型,如升压:: any_iterator做(从http://www.boost.org/ DOC /库/ 1_52_0 /库/范围/ DOC/HTML /范围/参考/范围/ any_range.html)。 –