fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template<typename T>
  5. class Proxy
  6. {
  7. public:
  8. enum class State
  9. {
  10. NEVER_SET = 0,
  11. SET,
  12. UNSET
  13. };
  14. operator const T& () const
  15. {
  16. if ( _state != State::SET )
  17. {
  18. std::cout << "EXCEPTION" << std::endl;
  19. // TODO throw exception
  20. }
  21. return _data;
  22. }
  23. Proxy<T>& operator=(const T& val)
  24. {
  25. _data = val;
  26. _state = State::SET;
  27. return (*this);
  28. }
  29. Proxy<T>& operator+=(const T& val)
  30. {
  31. _data = (*this) + val;
  32. _state = State::SET;
  33. return (*this);
  34. }
  35. private:
  36. T _data;
  37. State _state = State::NEVER_SET;
  38. };
  39.  
  40. class Tape
  41. {
  42. };
  43.  
  44. template<typename T>
  45. class tape : public Tape
  46. {
  47. public:
  48. const Proxy<T>& operator[](int idx) const
  49. {
  50. return operator[](idx);
  51. }
  52. Proxy<T>& operator[](int idx)
  53. {
  54. if ( idx >= data.size() )
  55. {
  56. data.resize(idx + 1);
  57. }
  58. return data[idx];
  59. }
  60. private:
  61. std::vector< Proxy<T> > data;
  62. };
  63.  
  64. class CRIXUS
  65. {
  66. public:
  67. virtual void Go() final {};
  68. protected:
  69. virtual void Pre() {};
  70. virtual void Post() {};
  71. virtual void Step() = 0;
  72. };
  73.  
  74. class CRIXUS_MA : public CRIXUS
  75. {
  76. public:
  77. int window = 30;
  78. tape<double> input;
  79. tape<double> output;
  80. protected:
  81. virtual void Step()
  82. {
  83. double sum = 0;
  84. for ( int j = 0; j < window; j++ )
  85. {
  86. sum += input[-j];
  87. }
  88. output[0] = sum / window;
  89. }
  90. };
  91.  
  92. int main()
  93. {
  94. }
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty