Today I came across some C++ code which I thought was not going to compile:
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<vector<int>> vectorOfVectors = { { 2, 3, 5 }, { 1, 2, 3 } };
sort(vectorOfVectors.begin(), vectorOfVectors.end());
return 0;
}
As far as I know, there is no default comparator in C++ for vectors of ints, so one would have to implement a custom comparator or lambda function in order to pass it to the sort() function.
However, the fact that this code compiled made me want to ask this question; is there a default comparator for vectors of ints? Is there one for floats, doubles, and so on? Or does the compiler automatically generate it? It should be noted that this way of sorting a vector of vectors is nowhere to be found online.
Thanks in advance!
vector<anything>becomes comparable. And since this is comparable,vector<vector<anything>>must be comparable as well.