unexpected unique_copy constness issue
I was trying to come up with a neat STL-heavy response to this thread
about multimaps:
http://groups.google.com/group/comp.lang.c++/browse_frm/thread/5a3732e0cbaab918/35e6796296b79797?q=multimap&rnum=3#35e6796296b79797
My implementation involved using unique_copy to uniquify the set of
keys. However, the compiler (gcc 4.0.2) complains because it's trying
to (internally) use
std::pair<const int, int> & std::pair<const int,
int>::operator=(std::pair<const int,int> const&)
which it has synthesized. The code is as follows:
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> value;
bool cmp(value const& lhs, value const& rhs)
{
return lhs.first == rhs.first;
}
int main()
{
typedef map<int, int> m_t;
m_t m;
vector<value> v;
copy(m.begin(),
m.end(),
back_inserter<vector<value> >(v));
unique_copy(m.begin(),
m.end(),
back_inserter<vector<value> >(v),
cmp);
return EXIT_SUCCESS;
}
Note that the call to copy() proceeds without problem. I can
understand why the map holds std::pair<const int, int> rather than
std::pair<int, int>, but I don't see why it would need to assign to a
value of that type to do unique_copy. Especially because copy() works
just fine... anyone got an idea here?
Luke