fork download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.  
  7. template<typename T>
  8. struct foo {
  9. vector<T> bar;
  10. };
  11.  
  12. template<typename T>
  13. void set(foo<T> &foo) {
  14. for (auto &el: foo.bar) {
  15. el = {};
  16. }
  17. }
  18.  
  19. template<>
  20. void set<int>(foo<int> &foo) {
  21. for (auto &el: foo.bar) {
  22. el = 111;
  23. }
  24. }
  25.  
  26. template<>
  27. void set<string>(foo<string> &foo) {
  28. for (auto &el: foo.bar) {
  29. el = "dupa";
  30. }
  31. }
  32.  
  33. template<typename T>
  34. void print(foo<T> const &foo) {
  35. for (auto const &el : foo.bar) {
  36. cout << el << " ";
  37. }
  38. cout << endl;
  39. }
  40.  
  41. int main() {
  42. foo<int> f1 = { {1, 2, 3} };
  43. foo<double> f2 = { {1.0, 2.0, 3.0} };
  44. foo<string> f3 = { {"ala", "ma", "kota"} };
  45.  
  46. set(f1);
  47. print(f1);
  48.  
  49. set(f2);
  50. print(f2);
  51.  
  52. set(f3);
  53. print(f3);
  54. }
Success #stdin #stdout 0s 4804KB
stdin
Standard input is empty
stdout
111 111 111 
0 0 0 
dupa dupa dupa