Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename _Forward_iterator, typename _Function, unsigned int _Chunk_size>
- class _Parallel_for_each_helper
- {
- public:
- typedef typename std::iterator_traits<_Forward_iterator>::value_type _Value_type;
- static const unsigned int _Size = _Chunk_size;
- _Parallel_for_each_helper(_Forward_iterator& _First, const _Forward_iterator& _Last, const _Function& _Func) :
- _M_function(_Func), _M_len(0)
- {
- // Add a batch of work items to this functor's array
- for (unsigned int _Index=0; (_Index < _Size) && (_First != _Last); _Index++)
- {
- _M_element[_M_len++] = &(*_First++);
- }
- }
- void operator()() const
- {
- // Invoke parallel_for on the batched up array of elements
- _Parallel_for_impl(0U, _M_len, 1U,
- [this] (unsigned int _Index)
- {
- _M_function(*(_M_element[_Index]));
- }
- );
- }
- private:
- const _Function& _M_function;
- _Value_type * _M_element[_Size];
- unsigned int _M_len;
- _Parallel_for_each_helper const & operator=(_Parallel_for_each_helper const&); // no assignment operator
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement