map
is an std::unordered_map
. T
has a move constructor.
void foo(const std::string& s, T&& t) {
map.insert(std::pair<std::string, T>(s, t));
}
T t;
foo("", std::move(t));
Why isn't this code calling template<class U, class V> std::pair(U&& a, V&& b)
?
Why do we need to use std::move(t)
to get the right behavior?
void foo(const std::string& s, T&& t) {
map.insert(std::pair<std::string, T>(s, std::move(t)));
}