Version 1 is probably a bad idea, things like f(x.getData()) may or may not move, depending on f signature. In general, we want any move be explicit in the code, so you should have at least:
std::vector<int>&& getData() && { return std::move(data_); }
So now the movement should be explicit: f( std::move(x).getData() ) , and you probably want to provide overload for const & just for observation.
Version 2 will be approved if it has a different name. In my experience, 99% of people perceive getX as an operation without modification. Better name it releaseData , which is consistent with the name unique_ptr::release .
source share