Suppose I have a C++ function like the following:
int foo (vector<int>& v1, vector<int>& v2){
vector<int> long_vec;
if ( v1.size() >= v2.size())
long_vec = v1;
else
long_vec = v2;
// do stuff with "long_vec" ...
}
I don't want to copy the contents in "v1" or "v2" into "long_vec". Instead, I just want to know whichever "v1" or "v2" is longer, and use it. I know something like the vector reference like the following:
vector<int>& long_ref = v1;
But this reference has to be initialized when declared. Basically I want the following behavior:
int foo (vector<int>& v1, vector<int>& v2){
//vector<int> long_vec;
vector<int>& long_vec; // won't compile
if ( v1.size() >= v2.size())
long_vec = v1;
else
long_vec = v2;
// do stuff with "long_vec" ...
}
Is there a way to achieve this. Thank you very much.