Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Lars_D_2
Beginner
116 Views

parallel_for_each on std::vector<std::unique_ptr> >

 

Dear community,

I'm trying to execute a parallel_for_each on a std::vector of unique_ptr.

std::vector<std::unique_ptr<SomeClass> > foo;
foo.fillData()
parallel_for_each(
    foo.begin()
  , foo.end()
  , [&] (std::unique_ptr<SomeClass>& singleFoo) { singleFoo -> method();}
);

However, compiling this code results in an error, because the "implicitly deleted copy constructor" (of the unique_ptr) is called. 

I think the issue is similar to using the following code

for (auto singleFoo : foo) {
  singleFoo -> method();
}

which does not compile with the same error, but the following for sure compiles:

for (auto& singleFoo : foo) {
  singleFoo -> method();
}

Would you please be so kind to assist me in this case? What do I need to change to have parallel_for_each use the reference (as provided in the lambda declaration) instead of copying the items?

Thanks a lot in advance,

Lars

Edit: Corrected second example as found by Raf. Forget the & behind the auto.

0 Kudos
2 Replies
RafSchietekat
Black Belt
116 Views

Try again with TBB 4.4 update 1 or later (the latest stable release is 4.4 update 2).

(2015-12-12 Added) I suppose you meant "auto&" rather than "auto" in the second code snippet?

Lars_D_2
Beginner
116 Views

Hi Raf,

thanks for your answer. I will try with the most recent TBB version. And yes... I forgot the & behind the auto in the second example. Thanks for pointing that out. I corrected that.

Thanks again,

Lars

Reply