fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Index2D {
  6. int row = -1, column = -1;
  7.  
  8. Index2D(int r): row{r} {}
  9. Index2D & operator,(int c) { column = c; return *this; }
  10. };
  11.  
  12. Index2D operator""row(unsigned long long int r) { return Index2D{static_cast<int>(r)}; }
  13. int operator""col(unsigned long long int c) { return static_cast<int>(c); }
  14.  
  15. class Matrix {
  16. public:
  17. int operator[](const Index2D & idx) {
  18. cout << "Element at row " << idx.row << " and column " << idx.column << " is ";
  19. return 42;
  20. }
  21. };
  22.  
  23. int main() {
  24. Matrix m;
  25.  
  26. cout << m[100'500row, 13col] << endl;
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Element at row 100500 and column 13 is 42