4 ms·
I'll bite. std::vector<std::pair<float, std::string>> in_order; std::transform(data.begin(), data.end(), std::back_inserter(in_order), [](
by Wehrdo 9y 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 https://repl.it/repls/RepentantGentleKudu
- jdashg 9y agoTemplates, auto, and type toys can give you some serious build-your-own syntactic sugar: https://repl.it/repls/PleasingLovingQueenslandheeler https://repl.it/repls/PleasingLovingQueenslandheeler Pulling things out of tuples isn't great, though.