#include <vector>
#include <iostream>
#include <functional> // Necessário para usar o std::less
using namespace std;
// Sobrecarrega o operador de menor para a classe `vector`
bool operator<(const vector<int>& a, const vector<int>& b)
{
vector<int>::const_iterator aIt = a.begin();
vector<int>::const_iterator bIt = b.begin();
bool ret = true;
while(aIt != a.end() && bIt != b.end())
{
//if(*aIt >= *bIt) // <== Mais simples e mais claro. Portanto, melhor.
if(!less<int>()(*aIt, *bIt))
{
ret = false;
break;
}
++aIt;
++bIt;
}
return ret;
}
int main()
{
vector<int> v1 = {5, 3, 8};
vector<int> v2 = {4, 1, 6};
// Imprime os vetores para conferência
cout << "v1: ";
for (auto i: v1)
std::cout << i << ' ';
cout << endl;
cout << "v2: ";
for (auto i: v2)
std::cout << i << ' ';
cout << endl;
// Usa diretamente o operador para verificar se v2 é menor do que v1
cout << "v2 < v1? " << (v2 < v1 ? "SIM" : "NAO") << endl;
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4gLy8gTmVjZXNzw6FyaW8gcGFyYSB1c2FyIG8gc3RkOjpsZXNzCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gU29icmVjYXJyZWdhIG8gb3BlcmFkb3IgZGUgbWVub3IgcGFyYSBhIGNsYXNzZSBgdmVjdG9yYApib29sIG9wZXJhdG9yPChjb25zdCB2ZWN0b3I8aW50PiYgYSwgY29uc3QgdmVjdG9yPGludD4mIGIpCnsKCXZlY3RvcjxpbnQ+Ojpjb25zdF9pdGVyYXRvciBhSXQgPSBhLmJlZ2luKCk7Cgl2ZWN0b3I8aW50Pjo6Y29uc3RfaXRlcmF0b3IgYkl0ID0gYi5iZWdpbigpOwoJCglib29sIHJldCA9IHRydWU7Cgl3aGlsZShhSXQgIT0gYS5lbmQoKSAmJiBiSXQgIT0gYi5lbmQoKSkKCXsKCQkvL2lmKCphSXQgPj0gKmJJdCkgLy8gPD09IE1haXMgc2lt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