1

I have an unordered map with string keys and a tuple of three strings and one int. How can I access the individual tuples to set them.

Given:

std::unordered_map<string,std::tuple<string, string, string,int>> foo_data_by_username;

How can I set the individual tuple values of say foo_data_by_username[some_user];

1
  • 2
    Beware that using tuples can infect your code with magic numbers (std::get<0> -- what is "0" supposed to mean)? You might be better off using a custom POD type so that you can give each piece of data a useful name, as well as the ability to add/remove members without having to adjust tuple indices everywhere in your code. Commented Apr 3, 2017 at 17:09

1 Answer 1

6
std::get<0>(foo_data_by_username[some_user]) = "new string";

Where 0 is whichever index of the tuple you're interested in.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.