multimap, equal_range and const_iterator problem
807578Jan 11 2008 — edited Jan 11 2008Can anyone explain why the following code below will not compile under Sun Studio 11 and Sun Studio 12? I get errors on the bolded line.
#include <map>
typedef std::multimap<int, int> maptype_t;
typedef maptype_t::iterator iter_t;
typedef maptype_t::const_iterator const_iter_t;
int main()
{
maptype_t mymap;
std::pair<iter_t, iter_t> result;
result = mymap.equal_range(10);
std::pair<const_iter_t, const_iter_t> result2;
result2 = mymap.equal_range(10);
}
The above code compiles fine in GCC 4.x (g++ -Wall -pedantic -ansi) and Visual C++ 8.0 (cl /EHsc /W4). Both Sun Studio 11 & 12 compilers issue an error that effectively says you can't cast from a std::pair<iterator, iterator> to a std::pair<const_iterator, const_iterator>. That leads me to believe that the compiler is getting confused about which version of equal_range (const vs non-const) it should be invoking.
Edited by: alyandon on Jan 11, 2008 12:33 PM