fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <vector>
  4. #include <utility>
  5. #include <cassert>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. struct Object {
  11. int id;
  12. };
  13.  
  14. int main()
  15. {
  16. list<Object> objectList;
  17. list<int> idList;
  18.  
  19. assert( objectList.size() == idList.size() );
  20. std::vector<std::pair<int,Object>> wrapper( idList.size() );
  21. auto idList_it = std::begin( idList );
  22. auto objectList_it = std::begin( objectList );
  23. for( auto& e: wrapper )
  24. e = std::make_pair( *idList_it++, *objectList_it++ );
  25.  
  26. std::sort( wrapper.begin(), wrapper.end(),
  27. [](const std::pair<int,Object>& a, const std::pair<int,Object>& b) -> bool
  28. { return a.first<b.first; }
  29. );
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty