fork download
  1. #ifdef USE_TBB
  2. #include <tbb/parallel_for.h>
  3. #endif //USE_TBB
  4.  
  5. #include <iostream>
  6.  
  7. namespace serial {
  8. template<typename Count, typename UnaryFunc>
  9. void numeric_for(Count first, Count last, UnaryFunc f) {
  10. while(first!=last) {
  11. f(first);
  12. ++first;
  13. }
  14. }
  15. }
  16.  
  17. namespace compat {
  18. template<typename Count, typename UnaryFunc>
  19. void numeric_for(Count first, Count last, UnaryFunc f) {
  20. #ifdef USE_TBB
  21. tbb::parallel_for(first, last, f);
  22. #else
  23. serial::numeric_for(first, last, f);
  24. #endif
  25. }
  26. }
  27.  
  28. int main() {
  29. compat::numeric_for(
  30. 1,
  31. 30,
  32. [](int i){ std::cout << i << '\t'; }
  33. );
  34. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20	21	22	23	24	25	26	27	28	29