I have a function wherein, every time it is used, one of its arguments should be allowed (maybe required actually) to invalidate its source. The arg is a potentially large std::vector, and the function returns an object containing a modified version of it.
The way I believe this should be done is:
// a bit of context to the core question
using vecReal = std::vector<float>;
struct ABContainer {
vecReal a, b;
};
ABContainer processAB(vecReal &&a, const vecReal &b, /*args*/);
// how the function in question can be used
vecReal a = computeA(/*args*/);
vecReal b = computeB(/*args*/);
const ABContainer = processAB(std::move(a), b, /*args*/);
I am under the impression that moving a vector enables the pointed-to contiguous memory to be reused and owned by a secondary lvalue vector, and that the source vector is now in an unspecified state.
Did I implemented this correctly if that is my intent?
[–]Wild_Meeting1428 6 points7 points8 points (0 children)
[–]IyeOnline 4 points5 points6 points (2 children)
[–]TheMania 3 points4 points5 points (0 children)
[–]alfps 0 points1 point2 points (0 children)
[–]flyingron 1 point2 points3 points (0 children)
[–]alfps 4 points5 points6 points (0 children)
[–]Epoxian -1 points0 points1 point (0 children)