0

Say I have this function:

vector<int> func(vector<int>& a) {
    vector<int> res;
    for (int x : a) {
        res.push_back(a*2);
    }
    return res;
}

As far as I'm aware, when func returns, res is copied onto the stack which basically repeats an O(n) operation. Does C++ have capabilities to return a vector here without copying the entire thing ?

doctopus
  • 5,349
  • 8
  • 53
  • 105

0 Answers0