If I want to compare two vectors in lexicographical order, I can do as follows:
int main() {
std::vector<int> a{0, 7, 8, 9};
std::vector<int> b{1, 2, 3, 4};
std::cout << std::boolalpha;
std::cout << "a < b returns " << (a < b) << '\n';
}
But doing the same in reverse order fails to compile:
int main() {
std::vector<int> a{3, 2, 1};
std::vector<int> b{9, 8, 7, 6};
std::cout << std::boolalpha;
std::cout << "revrese a < reverse b returns " << ((a | std::views::reverse) < (b | std::views::reverse)) << '\n';
}
The latter code fails with:
<source>:23:81: error: no match for 'operator<' (operand types are 'std::ranges::reverse_view<std::ranges::ref_view<std::vector<int> > >' and 'std::ranges::reverse_view<std::ranges::ref_view<std::vector<int> > >')
23 | std::cout << "reverse a < reverse b returns " << ((a | std::views::reverse) < (b | std::views::reverse)) << '\n';
| ~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| reverse_view<[...]> reverse_view<[...]>
So, how to do achieve this properly?
I needed this because, I was creating a custom big integer class. In that, I was storing nodes in little endian order. Now, to compare if two integers are equal, first I compare their sizes. Then I would need to compare equal sized vectors in lexicographical order of their reverse view.
<, the question you propose as dupe is about equality, where reversed or not does not matter<reversed.==/ equality and lexicographical comparison /<are totally different. The question you link is about the former, the question here is about the latter. The answers on the question you link focus on equality because thats what is being asked for there, but not here.