fork(6) download
  1. #include <iostream>
  2. #include <functional>
  3. #include <iterator>
  4. #include <algorithm>
  5. #include <string>
  6. #include <list>
  7. #include <vector>
  8. #include <random>
  9.  
  10. int main() {
  11. std::list<std::string> l{"Hello", "Stack", "Over", "flow", "!!"};
  12. std::vector<std::reference_wrapper<std::string>> v(l.begin(), l.end());
  13. std::random_device rd;
  14. std::mt19937 generator(rd());
  15. std::shuffle(v.begin(), v.end(), generator);
  16. std::cout << "Original list:\n";
  17. std::copy(l.begin(), l.end(), std::ostream_iterator<std::string>(std::cout, " "));
  18. std::cout << "\nShuffled view:\n";
  19. std::copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, " "));
  20. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Original list:
Hello Stack Over flow !! 
Shuffled view:
Hello Over !! Stack flow