fork download
  1. #include <boost/numeric/ublas/vector.hpp>
  2. #include <iomanip>
  3. #include <stdio.h>
  4.  
  5. namespace ublas = boost::numeric::ublas;
  6.  
  7. template <class T> class Vector
  8. {
  9. private:
  10.  
  11. ublas::vector<T> m_ublas_vec;
  12. unsigned m_size;
  13.  
  14. public:
  15.  
  16. Vector(unsigned s){
  17. m_size = s;
  18. m_ublas_vec.resize(m_size);
  19. }
  20.  
  21. T &operator () (unsigned idx) {
  22. if(idx >= m_size){
  23. perror("ERROR: Index out of bounds!\n");
  24. exit(1);
  25. }
  26. }
  27.  
  28. // Right-multiply by scalar.
  29. template <class TT, class S>
  30. friend Vector<TT> operator * (const Vector<TT> &, S);
  31.  
  32. // Left multiply by scalar.
  33. template <class TT, class S>
  34. friend Vector<TT> operator * (S, const Vector<TT> &);
  35. };
  36.  
  37. template <class T, class S>
  38. Vector<T> operator * (const Vector<T> &v_in, S scalar){
  39. Vector<T> v_out (v_in.m_size);
  40. v_out.m_ublas_vec = v_in.m_ublas_vec*static_cast<T>(scalar);
  41. return v_out;
  42. }
  43.  
  44. template <class T, class S>
  45. Vector<T> operator * (S scalar, const Vector<T> &v_in){
  46. Vector<T> v_out (v_in.m_size);
  47. v_out.m_ublas_vec = v_in.m_ublas_vec*static_cast<T>(scalar);
  48. return v_out;
  49. }
  50.  
  51. int main()
  52. {
  53. Vector<int> ss(4);
  54. ss*2;
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
Standard output is empty