SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4.  
  5. using namespace std;
  6.  
  7. template<typename T>
  8. class Matrix {
  9. private:
  10.     vector<vector<T>> m;
  11. public:
  12.     Matrix(const vector<vector<T>> &x) {
  13.         m = x;
  14.     }
  15.  
  16.     pair<size_t, size_t> size() const {
  17.         size_t a = m.size();
  18.         size_t b = m[0].size();
  19.         return {a, b};
  20.     }
  21.  
  22.     const vector<T> &operator[](size_t i) const {
  23.         return m[i];
  24.     }
  25. };
  26.  
  27. template<typename T>
  28. std::ostream &operator<<(std::ostream &out, const Matrix<T> &m) {
  29.     for (long unsigned int i = 0; i < m.size().first; ++i) {
  30.         for (long unsigned int j = 0; j < m.size().second; ++j) {
  31.             if (j != 0 && j != m.size().second) {
  32.                 out << '\t';
  33.             }
  34.             out << m[i][j];
  35.         }
  36.         if (i != m.size().first) {
  37.             out << '\n';
  38.         }
  39.     }
  40.     return out;
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top