Advertisement
Guest User

Untitled

a guest
May 24th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1.  
  2. template <typename _Forward_iterator, typename _Function, unsigned int _Chunk_size>
  3. class _Parallel_for_each_helper
  4. {
  5. public:
  6. typedef typename std::iterator_traits<_Forward_iterator>::value_type _Value_type;
  7. static const unsigned int _Size = _Chunk_size;
  8.  
  9. _Parallel_for_each_helper(_Forward_iterator& _First, const _Forward_iterator& _Last, const _Function& _Func) :
  10. _M_function(_Func), _M_len(0)
  11. {
  12. // Add a batch of work items to this functor's array
  13. for (unsigned int _Index=0; (_Index < _Size) && (_First != _Last); _Index++)
  14. {
  15. _M_element[_M_len++] = &(*_First++);
  16. }
  17. }
  18.  
  19. void operator()() const
  20. {
  21. // Invoke parallel_for on the batched up array of elements
  22. _Parallel_for_impl(0U, _M_len, 1U,
  23. [this] (unsigned int _Index)
  24. {
  25. _M_function(*(_M_element[_Index]));
  26. }
  27. );
  28. }
  29.  
  30. private:
  31.  
  32. const _Function& _M_function;
  33. _Value_type * _M_element[_Size];
  34. unsigned int _M_len;
  35.  
  36. _Parallel_for_each_helper const & operator=(_Parallel_for_each_helper const&); // no assignment operator
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement