- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page