No instance of overloaded function error

Hi all,
I am new to cpp programming. I want to create a map with key as tuples and value as list. And trying to insert the same to the map.But it's not working
ERROR: No instance of overloaded function and not finding the solution. And the code is attached below.

#include <iostream>
#include <tuple>
#include <map>
#include <list>

int main() {
std::map<std::tuple<int,int,int, int>,std::list<int>> mp;
mp.insert({(1,0,1,0),{1,0,0,0}});
}

Thank you,
Shruthi LS
Hello Shruthi LS,

I know a little about "maps" and even less about "tuples".

My understand is that the map key needs to be a single data type like "bool", "char", "int", "double" or "std::string" and that the map ctor does not know what or how to use a tuple as a key. To much information to choose from. At least that is my guess for now.

Just a thought here and I am not sure if it would work, but I am thinking that a pointer to a tuple might work. At least it would be a single variable type with different addresses.

Someone who knows more will have a better answer.

Andy
In a prior thread, you wrote that you had experience with Python. Unlike Python, C++ does not have tuple literals. Instead, std::tuple is a user-defined class template like any other.

Use braces, not parentheses:
mp.insert({{1,0,1,0},{1,0,0,0}});

If you use the expression (1, 0, 1, 0), you get something with type int and the value 0. It uses the comma operator, which evaluates and discards its left argument.

If you asked your compiler to warn you about suspect code, it would have corrected you.
Last edited on

mp.insert({{1,0,1,0},{1,0,0,0}}) this is working. Thank you!
Topic archived. No new replies allowed.