0

我有以下无序多图:

std::tr1::unordered_multimap<unsigned int, unsigned int > duplicates;

我尝试使用

std::pair<std::tr1::unordered_multimap<unsigned int, unsigned int>,std::tr1::unordered_multimap<unsigned int, unsigned int> > range = duplicates.equal_range(id);

然后使用 for 循环获得多个结果:

for (std::tr1::unordered_multimap<unsigned int, unsigned int>::iterator it=range.first; it!=range.second; ++it)

但我收到以下错误:

ref_impl/core.cpp:306:84: error: conversion from 'std::tr1::unordered_multimap<unsigned int, unsigned int>' to non-scalar type 'std::tr1::_Hashtable<unsigned int, std::pair<const unsigned int, unsigned int>, std::allocator<std::pair<const unsigned int, unsigned int> >, std::_Select1st<std::pair<const unsigned int, unsigned int> >, std::equal_to<unsigned int>, std::tr1::hash<unsigned int>, std::tr1::__detail::_Mod_range_hashing, std::tr1::__detail::_Default_ranged_hash, std::tr1::__detail::_Prime_rehash_policy, false, false, false>::iterator {aka std::tr1::__detail::_Hashtable_iterator<std::pair<const unsigned int, unsigned int>, false, false>}' requested
ref_impl/core.cpp:306:101: error: no match for 'operator!=' in 'it != range.std::pair<std::tr1::unordered_multimap<unsigned int, unsigned int>, std::tr1::unordered_multimap<unsigned int, unsigned int> >::second'

有什么建议么?

4

2 回答 2

3

unordered_multimap::equal_range返回一对迭代器,而不是一对unordered_multimaps。将第二行更改为以下内容,一切正常:

typedef std::tr1::unordered_multimap<unsigned int, unsigned int>::iterator iterator;
std::pair<iterator, iterator> range = duplicates.equal_range(id);
于 2013-03-16T02:19:41.443 回答
1

您已声明range为一对无序映射,而不是无序映射迭代器。感谢上帝的汽车。你确定不能用?它会让你的生活变得更轻松:

auto range = duplicates.equal_range(id);

否则,您应该自由使用typedef.

于 2013-03-16T02:18:41.637 回答