fork(1) download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. struct execute {
  5. const unsigned long long n;
  6.  
  7. void operator() (std::function<void()> what) {
  8. for (auto i = 0; i < n; i++)
  9. what();
  10. }
  11.  
  12. void operator() (std::function<void(unsigned long long)> what) {
  13. for (auto i = 0; i < n; i++)
  14. what(i);
  15. }
  16. };
  17.  
  18. execute operator"" _times(unsigned long long n) {
  19. return execute{n};
  20. }
  21.  
  22. int main() {
  23. 3_times([]{
  24. std::cout << "bla" << std::endl;
  25. });
  26.  
  27. auto twice = 2_times;
  28.  
  29. twice([]{
  30. std::cout << "blup" << std::endl;
  31. });
  32.  
  33. 3_times([](auto i) {
  34. std::cout << "counting: " << i << std::endl;
  35. });
  36. }
  37.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
bla
bla
bla
blup
blup
counting: 0
counting: 1
counting: 2