How it can be better using template

Правка en1, от arjun17, 2018-08-19 13:52:45
#include <bits/stdc++.h>
using namespace std;

const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
/*const long long RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();*/


struct HASH {
    template <class T>
    std::size_t operator()(T x) const { 
        return hash<T>{}(x ^ RANDOM ); 
    }
};

int main(int argc, char const *argv[])
{
    unordered_map<int, int, HASH> table;
    /* unordered_map<long long, int, HASH> table; */

    return 0;
}

If my map key is int type I've to write const int RANDOM If my map key is long long type I've to write const long long RANDOM blah blah ......

How it can be better using Template?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en5 Английский arjun17 2018-08-19 13:58:27 13
en4 Английский arjun17 2018-08-19 13:56:53 30
en3 Английский arjun17 2018-08-19 13:54:52 77
en2 Английский arjun17 2018-08-19 13:53:33 8
en1 Английский arjun17 2018-08-19 13:52:45 779 Initial revision (published)