fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <vector>
  4. #include <string>//<string_view> doesn't work in this compiler!
  5. #include <cstdlib>
  6. #include <ctime>
  7.  
  8. template <typename Container>
  9. void func(const Container &c)
  10. {
  11. for(int i = 0; i < 10; ++i)
  12. {
  13. std::cout << c[rand() % c.size()];
  14. }
  15. }
  16.  
  17. int main()
  18. {
  19. std::srand(std::time(nullptr));
  20.  
  21. std::array<std::string/*_view*/, 2> a{"1","2"};
  22. func(a);
  23.  
  24. std::cout << std::endl;
  25.  
  26. std::vector<std::string/*_view*/> v{"1","2"};
  27. func(v);
  28.  
  29. std::cout << std::endl;
  30.  
  31. func<std::array<std::string/*_view*/, 2>>({"1","2"});
  32.  
  33. std::cout << std::endl;
  34.  
  35. func<std::vector<std::string/*_view*/>>({"1","2"});
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 5016KB
stdin
Standard input is empty
stdout
1211221212
1112122212
1211212121
1222111122