I was sorting a vector of vectors based on the last element of the individual vectors. But couldn't get it to work. Copilot gave me the following example:
#include <algorithm> #include <iostream> #include <vector> #include <ranges> int main() { std::vector<std::vector<int>> v = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; std::ranges::sort(v, {}, &std::vector<int>::back); for (const auto& vec : v) { for (const auto& elem : vec) { std::cout << elem << " "; } std::cout << "\n"; } } But it doesn't work with Godbolt g++ x86-64 trunk using -std=c++2b. It complains about "unresolved overloaded function type" for the third parameter (&std::vector::back).
My question, is this supposed to work?
Here is a link to godbolt.org, https://godbolt.org/z/qrbGcc48f.
back, and the compiler doesn't know which one to pick.