00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __TBB_parallel_for_each_H
00030 #define __TBB_parallel_for_each_H
00031
00032 #include "parallel_do.h"
00033
00034 namespace tbb {
00035
00037 namespace internal {
00038
00039 template <typename Function, typename Iterator>
00040 class parallel_for_each_body : internal::no_assign {
00041 const Function &my_func;
00042 public:
00043 parallel_for_each_body(const Function &_func) : my_func(_func) {}
00044 parallel_for_each_body(const parallel_for_each_body<Function, Iterator> &_caller) : my_func(_caller.my_func) {}
00045
00046 void operator() ( typename std::iterator_traits<Iterator>::reference value ) const {
00047 my_func(value);
00048 }
00049 };
00050 }
00052
00056
00057
00058 #if __TBB_TASK_GROUP_CONTEXT
00059 template<typename InputIterator, typename Function>
00060 void parallel_for_each(InputIterator first, InputIterator last, const Function& f, task_group_context &context) {
00061 internal::parallel_for_each_body<Function, InputIterator> body(f);
00062 tbb::parallel_do (first, last, body, context);
00063 }
00064 #endif
00065
00067 template<typename InputIterator, typename Function>
00068 void parallel_for_each(InputIterator first, InputIterator last, const Function& f) {
00069 internal::parallel_for_each_body<Function, InputIterator> body(f);
00070 tbb::parallel_do (first, last, body);
00071 }
00072
00074
00075 }
00076
00077 #endif