unordered_map sort problem

Oct 3, 2011 at 2:26pm
Hello,
I've come to the situation i need to sort unordered map. Here's the example code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class CGridSortFunc
{
public:
    CGridSortFunc(ROWCOL nRowCol) : m_nColToSort(nRowCol) {}

    bool operator()(const std::unordered_map<unsigned int, std::vector<CString> >::const_iterator &lhs,
                    const std::unordered_map<unsigned int, std::vector<CString> >::const_iterator &rhs)
    {
        //do the comparison
        return //result
    }
private:
    ROWCOL m_nColToSort;
};

//some function
std::unordered_map<unsigned int, std::vector<CString> > mapValues;

//filling the map...

CGridSortFunc func(nSomeInt);
std::sort(mapValues.begin(), mapValues.end(), func);

but i get the following compile errors:

d:\utils\stlport\stlport\stl\_algo.c(1003) : error C2784: 'struct stlp_std::complex<_Tp> __cdecl stlp_std::operator -(const struct stlp_std::complex<_Tp> &,const struct stlp_std::complex<_Tp> &)' : could not deduce template argument for 'const struc
t stlp_std::complex<_Tp> &' from 'struct stlp_std::priv::_Ht_It<class stlp_std::priv::_SL__It<struct stlp_std::pair<unsigned int const ,class stlp_std::vector<class CString,class stlp_std::allocator<class CString> > >,struct stlp_std::_N_Tr<struct s
tlp_std::pair<unsigned int const ,class stlp_std::vector<class CString,class stlp_std::allocator<class CString> > > > >,struct stlp_std::priv::_NonLocalUnorderedMapTraitsT<struct stlp_std::pair<unsigned int const ,class stlp_std::vector<class CStrin
g,class stlp_std::allocator<class CString> > > > >'
        d:\matrixe17\matrixkozijn tools\mxkgrids\source\grid\mxkappendgridtempl.h(500) : see reference to function template instantiation 'void __cdecl stlp_std::sort(struct stlp_std::priv::_Ht_It<class stlp_std::priv::_SL__It<struct stlp_std::pair<
unsigned int const ,class stlp_std::vector<class CString,class stlp_std::allocator<class CString> > >,struct stlp_std::_N_Tr<struct stlp_std::pair<unsigned int const ,class stlp_std::vector<class CString,class stlp_std::allocator<class CString> > > 
> >,struct stlp_std::priv::_NonLocalUnorderedMapTraitsT<struct stlp_std::pair<unsigned int const ,class stlp_std::vector<class CString,class stlp_std::allocator<class CString> > > > >,struct stlp_std::priv::_Ht_It<class stlp_std::priv::_SL__It<struc
t stlp_std::pair<unsigned int const ,class stlp_std::vector<class CString,class stlp_std::allocator<class CString> > >,struct stlp_std::_N_Tr<struct stlp_std::pair<unsigned int const ,class stlp_std::vector<class CString,class stlp_std::allocator<cl
ass CString> > > > >,struct stlp_std::priv::_NonLocalUnorderedMapTraitsT<struct stlp_std::pair<unsigned int const ,class stlp_std::vector<class CString,class stlp_std::allocator<class CString> > > > >,class CGridSortFunc)' being compiled


I've tried to give the sort function std::unordered_map, std::unordered_map::iterator and std::pair with the map arguments mentioned in code as template argument, but with no luck. Anyone know how to make this correctly or have any small example of how to use sort function with unordered_map?
Oct 3, 2011 at 2:35pm
I am really not sure how you can sort an unordered_map as its element positions are determined by the application of a hash function.
Oct 3, 2011 at 3:06pm
You may be right. At that case i'll use map instead or make a class with vector and int members.
Topic archived. No new replies allowed.