I am looking for a recommended way to convert concurrent_vectorfrom a PPL library to a regular std :: vector.
I have a function that returns its results in std::vector, but may or may not use parallel algorithms inside. I am currently using insertto copy elements from a parallel vector to a normal vector:
#ifdef PARALLEL
std::vector<Foo> Bar() {
concurrency::concurrent_vector<Foo> cv;
std::vector<Foo> sv;
sv.insert(sv.begin(), cv.begin(), cv.end());
return sv;
}
#else
std::vector<Foo> Bar() {
std::vector<Foo> sv;
return sv;
}
#endif
Although the performance of the insert operation is not real output at the moment (compared to the body of the function), it just seems unnecessary, and I wonder if there is a better solution (Btw .: Foois a simple POD that cannot be moved).
Ideally, I would like to have something like this
std::vector<Foo> Bar() {
concurrency::concurrent_vector<Foo> cv;
return static_cast<std::vector<Foo>>(cv);
}
or at least
std::vector<Foo> Bar() {
concurrency::concurrent_vector<Foo> cv;
std::vector<Foo> sv(std::move(cv));
return sv;
}
Are there any suggestions on how to do this correctly?
EDIT:
, ( ):
std::vector<Foo> Bar() {
concurrency::concurrent_vector<Foo> cv;
return std::vector<Foo>(cv.begin(), cv.end());
}
( ) , .
EDIT2:
, - , ( std::vector), RVO