Martins3 / refresh.nvim

immature and frenzy thoughts
0 stars 0 forks source link

cpp #6

Open Martins3 opened 3 years ago

Martins3 commented 3 years ago
Martins3 commented 3 years ago

cpp primer

Martins3 commented 3 years ago
Martins3 commented 3 years ago

objects

primer

Martins3 commented 3 years ago
  1. create my comparator for a map
    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

  1. priority_queue use similar style too !
    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

Martins3 commented 3 years ago

If k does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value.

Martins3 commented 3 years ago