|
|
|
|
|
by Wehrdo
3105 days ago
|
|
I'll bite. std::vector<std::pair<float, std::string>> in_order;
std::transform(data.begin(), data.end(), std::back_inserter(in_order),
[](auto& item) {return std::make_pair(item.weight, item.name);});
std::sort(in_order.begin(), in_order.end(), std::greater<>());
While I won't claim it to be as elegant as Python, it doesn't seem too ugly. Does anybody have an idea about how `auto` could be utilized to avoid the long vector<pair...> type declaration?For the adventurous: https://repl.it/repls/RepentantGentleKudu |
|
Pulling things out of tuples isn't great, though.