fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Matrix {
  5.  
  6. struct Adder {
  7. Matrix& m;
  8. int index;
  9.  
  10. Adder(Matrix& m) : m(m), index(1) {}
  11.  
  12. Adder& operator,(float value) {
  13. m.set(index++, value);
  14. return *this;
  15. }
  16.  
  17. };
  18.  
  19. void set(int index, float value) {
  20. cout << "Matrix[" << index << "] = " << value << endl;
  21. }
  22.  
  23. Adder operator<<(float value) {
  24. set(0, value);
  25. return Adder(*this);
  26. }
  27.  
  28. };
  29.  
  30.  
  31. int main() {
  32. Matrix mat;
  33. mat << 5, 10, 15, 20;
  34.  
  35. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
Matrix[0] = 5
Matrix[1] = 10
Matrix[2] = 15
Matrix[3] = 20