I have a function that sorts two vectors with the first of them as an ordering criterion. His signature
template<typename A, typename B>
void sort(A&& X, B&& Y)
{
..
}
The problem is that universal links would make senseless cases like
sort(vector<int>{ 2,1,3 }, vector<int>{ 3,1,2 });
where the rvalue will be destroyed afterwards (nonsense).
The job explicitly for lvalue does not work, since
template<typename A, typename B>
void sort(A& X, B& Y) ...
sort(vector<int>{2,1,3}, vector<int>{3,1,2});
for some reason the above compilation (I thought that only const lvalues are allowed to contact rvalues and extend their lifespan?).
If I add an constlvalue to the link, then the function will no longer be able to modify the vectors and sort them.
My questions:
1) , // (*), r l, const? - int& r = 20; ? ?
2) , lvalues, rvalue temporaries? ( , )
, ++