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