fork download
  1. #include <iostream>
  2. #include <initializer_list>
  3. #include <vector>
  4.  
  5. template<class T> class Matrix {
  6. public:
  7. Matrix() {std::cout << "Matrix() " << this << std::endl;}
  8. Matrix(int width,int height):w(width),h(height) {std::cout << "Matrix(" << w << "x" << h << ") " << this << std::endl;}
  9. ~Matrix() {std::cout << "Matrix(" << w << "x" << h << ") " << this << " goodbye" << std::endl;}
  10. private:
  11. int w,h;
  12. };
  13.  
  14. class NN {
  15. public:
  16. NN()=default;
  17. NN(const std::initializer_list<size_t> &l);
  18. private:
  19. std::vector<Matrix<double>> m_weights;
  20. };
  21.  
  22. NN::NN(const std::initializer_list<size_t> &l) {
  23. m_weights.reserve(l.size()-1); // or deal with move constructors
  24. auto itr = l.begin();
  25. for (auto next = itr + 1; next != l.end(); ++next, ++itr)
  26. {
  27. m_weights.emplace_back(*next, *itr);
  28. }
  29. }
  30.  
  31. int main() {
  32. NN test{2,3,3,2};
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
Matrix(3x2) 0x5638f59aae70
Matrix(3x3) 0x5638f59aae78
Matrix(2x3) 0x5638f59aae80
Matrix(3x2) 0x5638f59aae70 goodbye
Matrix(3x3) 0x5638f59aae78 goodbye
Matrix(2x3) 0x5638f59aae80 goodbye