Open Martins3 opened 3 years ago
primer
auto comp = [](const string& a, const string& b) { return a.length() < b.length(); };
map<string, string, decltype(comp)> my_map(comp);
comp is used in two place!
But, for hash containers, it's a bottle more tricky: https://stackoverflow.com/questions/17016175/c-unordered-map-using-a-custom-class-type-as-the-key
auto f = [](const MyStruct &struct1, const MyStruct &struct2) {
return (struct1.key < struct2.key);
};
priority_queue<MyStruct, vector<MyStruct>, decltype(f)> b(f);
sort : lambda, container : decltype
[x] how greater works?
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>,
std::greater<std::pair<int, int>>>
FF should define <
operator
class FF {
public:
int x;
int y;
bool operator < (const FF &right) const { return this.x < FF.x; }
bool operator > (const FF &right) const { return this.x > FF.x; }
};
typedef pair<int, FF> Elm;
priority_queue<Elm, vector