performance of emplace is worse than check followed by emplace
问题 I have a std::unordered_map with a value_type that does not have a default constructor so I cannot do the following auto k = get_key(); auto& v = my_map[k]; I ended up writing a helper function value_type& get_value(key_type& key) { return std::get<0>(my_map.emplace( std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(args_to_construct_value) ))->second; } but the performance was markedly worse (i.e. the value_type's constructor showed up in perf) than the following