【发布时间】:2015-09-10 07:20:41
【问题描述】:
如何在不复制 unordered_set 的情况下将(静态定义的)unordered_set 添加到 unordered_map?
我试过了:
std::unordered_map<int, std::unordered_set<std::string>> my_map;
for (int i=0; i<100; i++)
my_map.emplace(i, {"foo", "bar"});
还有这个:
std::unordered_map<int, std::unordered_set<std::string>> my_map;
for (int i=0; i<100; i++)
my_map.insert(i, std::move(std::unordered_set<std::string>({"foo", "bar"})));
但它们都没有编译,我得到了这些错误(分别):
error: no matching function for call to ‘std::unordered_map<int, std::unordered_set<std::basic_string<char> > >::emplace(int&, <brace-enclosed initializer list>)’
和
error: no matching function for call to ‘std::unordered_map<int, std::unordered_set<std::basic_string<char> > >::insert(int&, std::remove_reference<std::unordered_set<std::basic_string<char> > >::type)’
【问题讨论】:
-
这看起来更像是您想要
unordered_sets 的unordered_map(这不是您在问题中所说的)。请澄清。
标签: c++ c++11 move unordered-map emplace