Here is the a code similar to one I have:
for (auto &uptr : vector_of_unique_ptrs) { // 1
auto result = do_the_job_with_pointee(uptr.get()); // 2
record_intermidiate_result(result, std::move(uptr)); // 3
}
Here I have a vector of unique pointers to some objects (line 1).
I iterate over the vector (line 1) and do some work using the pointee (line 2).
After the job is done I need to take a result and pass the ownership to some other place (line 3).
The code compiles and executes without any problems, but I have feeling that it's not legal to move iteratee during iteration.
I "skimmed" though publicly available C++11 draft, but didn't find any clarifications on the subject.
Could anybody tell me is the code above legal or not?
Aucun commentaire:
Enregistrer un commentaire