Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tuple in unordered_map

Tags:

People also ask

How do you use a tuple on a map?

get(): It is used to access the tuple values and modify them, it accepts the index and tuple name as arguments to access a particular tuple element. What is map? Maps in C++ are associative containers that can store elements in a mapped fashion. Each element of a map has a key and the corresponding mapped value.

Is tuple hashable C++?

The answer is no, can't be done for all tuples, since a tuple is a variadic template type.

Is a collection of unordered set of tuples?

An unordered set of tuples is an unordered set in which each of the elements is a tuple. Note that by default an unordered set doesn't have the functionality of tuples. In simple words, one cannot declare an unordered set of tuples directly in C++. One have to pass a Hash function as an argument to the unordered set.

Are duplicates allowed in unordered_map?

Because unordered_map containers do not allow for duplicate keys, this means that the function actually returns 1 if an element with that key exists in the container, and zero otherwise.


I want to use tuple consisting of int,char,char in my unordered_map. I am doing like this:

#include <string> #include <unordered_map> #include <cstring> #include <iostream> #include <tuple>  using namespace std;  tuple <int,char,char> kk; unordered_map<kk,int> map;  int main() {     map[1,"c","b"]=23;     return 0; } 

but this gives me following errors:

map.cpp:9:21: error: type/value mismatch at argument 1 in template parameter list     for ‘template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> class    std::unordered_map’ map.cpp:9:21: error:   expected a type, got ‘kk’ map.cpp:9:21: error: template argument 3 is invalid map.cpp:9:21: error: template argument 4 is invalid map.cpp:9:21: error: template argument 5 is invalid map.cpp:9:26: error: invalid type in declaration before ‘;’ token map.cpp: In function ‘int main()’: map.cpp:14:16: error: assignment of read-only location ‘"b"[map]’ 

What I am doing wrong in this?