fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template<typename T>
  6. ostream& operator << (ostream& os, vector<T>& vec){
  7. for(int i=0; i<vec.size(); i++){
  8. os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  9. }
  10. return os;
  11. }
  12.  
  13. template<typename V, typename T>
  14. void fill(V& x, const T& val){
  15. x = val;
  16. }
  17.  
  18. template<typename V, typename T>
  19. void fill(vector<V>& vec, const T& val){
  20. for(auto& v: vec) fill(v, val);
  21. }
  22.  
  23. int main(){
  24. vector<vector<int>> A(3, vector<int>(3, 1));
  25. for(int i=0; i<3; i++) cout << A[i] << endl;
  26. cout << endl;
  27.  
  28. fill(A, 2);
  29. for(int i=0; i<3; i++) cout << A[i] << endl;
  30. cout << endl;
  31.  
  32. fill(A[1], 3);
  33. for(int i=0; i<3; i++) cout << A[i] << endl;
  34. cout << endl;
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
1 1 1
1 1 1
1 1 1

2 2 2
2 2 2
2 2 2

2 2 2
3 3 3
2 2 2