Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Goooood
//Title of this code #include <iostream> #include <list> #include <memory> using namespace std; template<class T1, class T2> class MyMap { public: struct Node { long key_hash; T2 value; Node(long key_hash) { this->key_hash = long(key_hash); } Node(long key_hash, T2 value) { this->key_hash = long(key_hash); this->value = T2(value); } Node(const Node& n) { *this = Node(n.key_hash, n.value); } }; typedef shared_ptr<Node> node_ptr; private: hash<T1> hashing; list<node_ptr> nodes; public: MyMap(){} ~MyMap(){} //MyMap(const MyMap&); MyMap& operator=(MyMap&&); T2& operator[](const T1&); }; template<class T1, class T2> MyMap<T1, T2>& MyMap<T1, T2>::operator=(MyMap&& m) { if (this == &m) return *this; nodes = move(m.nodes); return *this; } template<class T1, class T2> T2& MyMap<T1, T2>::operator[](const T1& key) { long key_hash = hashing(key); //typename list<Node*>::iterator it; if (!nodes.empty()) for (auto it = nodes.begin(); it != nodes.end(); ++it) { if ((*it)->key_hash == key_hash) return (*it)->value; } node_ptr node = node_ptr(new Node(key_hash)); nodes.push_back(node); return node->value; } int main() { MyMap<int,int> m; MyMap<int,int> n; m[0] = 10; n[0] = 20; m = move(n); m[0] = 30; n[0] = 40; cout << n[0] << " " << m[0] << endl; }
run
|
edit
|
history
|
help
0
Вывод элементов массива
Dejalo a la Suerte
return reference (gcc)
Test 1(2021)
Dar
integerDivision
finding factor
Minimum Vertices to Traverse Directed Graph
Test 14(2020)
runtime template mode processor