fork download
  1. #include <vector>
  2. #include <list>
  3. #include <functional>
  4. #include <algorithm>
  5. #include <iostream>
  6.  
  7. int main()
  8. {
  9. const std::list<int> lst { 5, 4, 9, 3, 1, 8, 0 } ;
  10. for( const int& i : lst ) std::cout << i << " (" << &i << ") " ;
  11. std::cout << '\n' ;
  12.  
  13. std::vector< std::reference_wrapper< const int > > vec( lst.begin(), lst.end() ) ;
  14. std::sort( vec.begin(), vec.end() ) ;
  15. for( const int& i : vec ) std::cout << i << " (" << &i << ") " ;
  16. std::cout << '\n' ;
  17. }
  18.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
5 (0x9b52010) 4 (0x9b52020) 9 (0x9b52030) 3 (0x9b52040) 1 (0x9b52050) 8 (0x9b52060) 0 (0x9b52070) 
0 (0x9b52070) 1 (0x9b52050) 3 (0x9b52040) 4 (0x9b52020) 5 (0x9b52010) 8 (0x9b52060) 9 (0x9b52030)