fork download
  1. #define NDEBUG
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <utility>
  6.  
  7. // AOO = At Or Operator[]
  8. #ifndef NDEBUG
  9. #define AOO(INDEX) .at(INDEX)
  10. #else
  11. #define AOO(INDEX) [INDEX]
  12. #endif
  13.  
  14. void testNormalUse()
  15. {
  16. std::vector<int> vec(100);
  17. vec AOO(50) = 5;
  18. std::cout << vec AOO(50) << std::endl;
  19. }
  20.  
  21. void testRequireConst()
  22. {
  23. const std::vector<int> vec(100, 5);
  24. std::cout << vec AOO(50) << std::endl;
  25. }
  26.  
  27. void testRvalueRef()
  28. {
  29. std::vector<int>vec(100, 5);
  30. std::cout << std::move(vec) AOO(50) << std::endl;
  31. }
  32.  
  33. void test2d()
  34. {
  35. std::vector<std::vector<int>> vec(100, std::vector<int>(100, 5));
  36. std::cout << vec AOO(50) AOO(50) << std::endl;
  37. }
  38.  
  39. int main() {
  40. testNormalUse();
  41. testRequireConst();
  42. testRvalueRef();
  43. test2d();
  44. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
5
5
5
5