I have:
vector of
unique_ptr
s of ObjectAvector of newly default constructed vector of ObjectB, and
a function in Object B that has signature
void f(unique_ptr<ObjectA> o)
.
(word Object omitted from here on)
How do I do Bvec[i].f(Avec[i])
for all 0 < i < length
in parallel?
I have tried using transform(Bvec.begin(), Bvec.end(), A.begin(), B.begin(), mem_fun_ref(&B::f))
, but it gives a bunch of errors and I'm not sure if it would even pass the right A as parameter, let alone allow me to move them. (&B::f(A.begin())
would not work as the last parameter either.
I have also thought of using for_each and then a lambda function, but not sure how to get the corresponding element. I thought of incrementing a counter, but then I don't think that parallelizes well (I could be wrong).
I can, of course, use a for loop from 0 to end, but I am pretty sure there is a simple thing I'm missing, and it is not parallel with a simple for loop.
Thanks.