Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Boost::Map迭代器转换为std::迭代器_Boost_Unordered Map - Fatal编程技术网

将Boost::Map迭代器转换为std::迭代器

将Boost::Map迭代器转换为std::迭代器,boost,unordered-map,Boost,Unordered Map,我正在为Boost无序映射容器编写包装器方法。在boost无序映射中,有一个方法begin()将迭代器返回到第一个元素。实际上,在我的包装类中,我希望从begin方法返回std::无序映射::迭代器,而不是boost::无序映射::迭代器。 示例代码: 模板 boost::无序地图m_myMap; boost::无序::无序映射::迭代器MyWrapper::Begin() { 返回m_myMap.begin(); } 在上面的代码中,我想返回std::Unordered_map::itera

我正在为Boost无序映射容器编写包装器方法。在boost无序映射中,有一个方法begin()将迭代器返回到第一个元素。实际上,在我的包装类中,我希望从begin方法返回std::无序映射::迭代器,而不是boost::无序映射::迭代器。 示例代码: 模板

boost::无序地图m_myMap;
boost::无序::无序映射::迭代器MyWrapper::Begin()
{
返回m_myMap.begin();
}
在上面的代码中,我想返回std::Unordered_map::iterator
请帮忙,你不能。C++是一种强类型语言。 你所能做的就是

  • 使用
    std::无序地图
  • 使用类型擦除隐藏实现(
    boost::any_迭代器
    boost::any_范围
我敏锐的感觉告诉我,您应该根据推导的模板参数类型来获取迭代器,而不是将它们硬编码到您的算法中

template <typename Iterator>
void foo_algo(Iterator begin, Iterator end, int some_data) {
...
模板
void foo_algo(迭代器开始、迭代器结束、int一些_数据){
...
template <typename Iterator>
void foo_algo(Iterator begin, Iterator end, int some_data) {
...