Is this the right way to use C++11 rvalue-references and move semantics to implement a convenience wrapper for std::reverse()?
template <class BIDirContainer> inline BIDirContainer&& reverse(BIDirContainer a) {
std::reverse(begin(a), end(a));
return std::move(a);
}
The code works in my test case but I am unsure its about performance: should I use && here or is it unneccesary?
I would say the right way to do it is to return by value from your function:
and then give
BIDirContainera move constructor if it doesn’t have one. Then this kind of expression:should move the contents of the temporary
ain yourreversefunction intobackwards.