↧
Answer by R Sahu for Why is const required for 'operator>' but not for 'operator
Use of std::sort(vec.begin(), vec.end()) depends only on the operator< function. It does not require that the function be able to work with const objects.std::greater, on the other hand, requires...
View ArticleAnswer by StoryTeller - Unslander Monica for Why is const required for...
You get different behaviors because you are in fact calling two different (overloaded) sort functions. In the first case you call the two parameter std::sort, which uses operator< directly. Since...
View ArticleWhy is const required for 'operator>' but not for 'operator
Consider this piece of code:#include <iostream>#include <vector>#include <algorithm>#include <functional>using namespace std;struct MyStruct{ int key; std::string stringValue;...
View Article