Diferente pentru blog/cpp11 intre reviziile #33 si #34

Nu exista diferente intre titluri.

Diferente intre continut:

  {"john", 18}, {"mary", 21}, {"anna", 19}
};
cout << "Anna is " << age["anna"] << " years old." << endl;
==
==
 
Using STL vectors, pairs or user defined objects as keys is a little trickier because you also need to provide the hash function.
== code(cpp) |
#include <unordered_set>
#include <vector>
 
using namespace std;
 
// Some user defined constants used for hashing.
const int B = 31;
const int MOD = 666013;
 
struct myhash {
  size_t operator()(const vector<int>& v) const {
    size_t value = 1;
    for (auto x: v) {
      value = (value * B + hash<int>()(x)) % MOD;
    }
    return value;
  }
};
 
...
 
unordered_set<vector<int>, myhash> s;
vector<int> v = {1, 2, 3};
s.insert(v);
...
==
 

Nu exista diferente intre securitate.

Topicul de forum nu a fost schimbat.