fork(1) download
  1. #include <list>
  2. #include <vector>
  3. #include <string>
  4. #include <set>
  5. #include <iostream>
  6. #include <iterator>
  7. #include <functional>
  8.  
  9. template <typename C1, typename C2>
  10. void assign(C1& target, const C2& source)
  11. {
  12. using std::begin; using std::end;
  13. target.assign(begin(source), end(source));
  14. }
  15.  
  16. template <typename C>
  17. void print(const C& c)
  18. {
  19. for (auto& e : c)
  20. std::cout << e << '\n';
  21.  
  22. std::cout << '\n';
  23. }
  24.  
  25. int main()
  26. {
  27. std::vector<std::string> v;
  28. std::list<const char*> list = { "aaa", "bbb", "ccc" };
  29. std::set<const char*, std::less<std::string>> set = { "one", "two", "three", "four" };
  30. const char* array[] = { "one", "two", "three", "four" };
  31.  
  32. assign(v, list);
  33. print(v);
  34.  
  35. assign(v, set);
  36. print(v);
  37.  
  38. assign(v, array);
  39. print(v);
  40. }
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
aaa
bbb
ccc

four
one
three
two

one
two
three
four