-1

I didn't find any documentation about map in OMNeT++. I'm trying to sort a map<int,double> by value, not by key, and erase some data.

I declare the map and iterator like this

std::map<int,double> Dlist;
std::map<int,double>::iterator it;

I tried

sort(Dlist.begin(), Dlist.end());

but there is an error.

Also the iterator doesn't return values

iterator.first
iterator.second
Julian Heinovski
  • 1,822
  • 3
  • 16
  • 27
  • 1
    This is a purely C++ programming question. It has, just like `std::map`, nothing to do with OMNeT++. Not to mention that sorting by value does not make any sense on a data structure like `std::map`. – Attila Jun 19 '18 at 17:13
  • thank you for you answer @ Attila ,All scenario is already done , an RSU receive wsm messages and store wsm Data (has an int type) on a map , I need to sort this map bye the value of data , I tried the code above but no result . – Ismail Bouhariche Jun 19 '18 at 17:26
  • Is this question answered? – Julian Heinovski Jul 22 '18 at 12:31

1 Answers1

1

First of all this is a pure C++ related problem, since you are using std::map.

std::sort sorts a container in place, therefore there is no iterator which you can access. Additionally, in the given code the declared iterator is not even used.

Secondly, I strongly doubt that you actually want to sort the map's values. Although this is technically possible, it makes no sense: Sorting std::map using value.

Instead you could copy all values from the map into a std::vector and then sort that vector. See Copy map values to vector in STL.

Julian Heinovski
  • 1,822
  • 3
  • 16
  • 27