I read the Stroustrup C ++ blog ( http://isocpp.org/blog/2014/12/myths-3 ) when I found the code snippet:
void do_my_sort(vector<double>& v)
{
sort(v,[](double x, double y) { return x>y; });
}
int main()
{
vector<double> vd;
do_my_sort(v);
}
Note that it sortdoes not use the traditional sort(v.begin(), v.end(), ...)one that Stroustrup explains:
I used the container version sort()to avoid explicit iterators.
However, I tried the same code in my C ++ 11 compiler, but could not compile it. I also tried the same thing in the C ++ 14 compiler using ideone, but it also does not compile, saying that there is no corresponding call to sort.
Why is this?
In addition, the following is mentioned in Straustupat:
I could go further and use the C ++ 14 comparison object:
sort(v,greater<>()); // sort v in decreasing order
great<>() sort ++ 11. , ++ 14?