Answer the question
In order to leave comments, you need to log in
C++ how to copy tuples from one container to another via an iterator?
So.
struct my_tuple_hasher
{
std::size_t operator()(const std::pair<std::string, std::string>& k) const
{
std::string s1, s2, s3;
std::tie(s1, s2, s3) = k;
return std::hash<std::string>()(s1) ^ std::hash<std::string>()(s2) ^ std::hash<std::string>()(s3);
}
};
std::unordered_map<std::tuple<std::string, std::string, std::string>, std::unique_ptr<SOMETHING>, my_tuple_hasher> m;
auto ob02 = std::unique_ptr<SOME_TYPE>(new SOME_TYPE());
ob02->... = ...;
m[std::make_tuple("Lorem", "ipsum", "1")] = std::move(ob02);
for (auto it = m.begin(); it != m.end(); ++it)
{
m2[it->first] = std::move(it->second);
}
tuple<string, string, string>
returns some kind of tr1::tuple<...>
Answer the question
In order to leave comments, you need to log in
1) Your hash operator just won't compile. You are trying to decompose a pair into three arguments.
2) In the hashing operator, the combination of hashes is not quite correct. See how boost::hash_combine is made, for example.
3) Check if the types are exactly the same. Better yet, create aliases for all long types and use them.
4) In principle, everything should work, and perhaps the problem is in the environment / flags. Get an online compiler like godbolt.org and try compiling there.
PS
I hope you are just experimenting and not writing a real project. This use of tuples is an overkill.
PPS
And English pronunciation tapl.
At me nothing swears. VS 2013.
The compiler's mention of "tuple" from the "tr1" namespace probably indicates that it's time for you to upgrade your tooling.
And probably instead of:
you wanted to do:
std::size_t operator()(const std::tuple<std::string, std::string, std::string>& k) const
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question