maps are sorted base on key. I think his trying to sort the value. ..

Alternative solution.

/* ugly coding */
template <template <typename ELEM,typename = std::allocator<ELEM> >
         class CONT,
         class T, class U>
inline CONT<U> getValues(const boost::unordered_map<T, U>& data)
{
    CONT<U> retCont;
    typedef typename boost::unordered_map<T, U>::value_type value_type;
    BOOST_FOREACH(value_type val, data)
    {
        retCont.push_back(val.second);
    }
    return retCont;
}


std::vector<int> countriesValue = getValues<std::vector, int, int>(countries);
std::sort(countriesValue.begin(), countriesValue.end());

On 8/8/07, Cory Nelson <phrosty@gmail.com> wrote:
On 8/8/07, Olaf van der Spek <olafvdspek@gmail.com > wrote:
> Hi,
>
> I'm trying to sort a map based on second, but I get all kinds of
> compiler errors and I have no idea what's wrong. A simple _1 > _2
> works fine, but that compares the maps themselves.
>
> Also, is there a better way to write the copy from map to vector or to
> sort the map in general?

maps are already sorted!  see the third template argument.  a simple
vec.insert(vec.end(), map.begin(), map.end()) will copy it.  did you
need something else?

--
Cory Nelson
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users