Update hlookup.h

This commit is contained in:
deal 2021-12-28 17:59:44 +08:00 committed by GitHub
parent ff332f667a
commit a982fdf3e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -7,6 +7,7 @@
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "tsl/robin_map.h"
#include "tsl/robin_set.h"
@ -47,13 +48,13 @@ using string_map = tsl::robin_map<std::string, _Valty, string_hash, equal_to>;
using string_set = tsl::robin_set<std::string, string_hash, equal_to>;
template <typename _Cont, typename _Valty>
inline auto set_item(_Cont& cont, std::string_view key, _Valty&& _Val)
inline auto set_item(_Cont& cont, std::string_view k, _Valty&& v)
{
typename _Cont::iterator it = cont.find(key);
typename _Cont::iterator it = cont.find(k);
if (it != cont.end())
it->second = std::move(_Val);
it->second = std::forward<_Valty>(v);
else
it = cont.emplace(std::string{key}, std::forward<_Valty>(_Val)).first;
it = cont.emplace(std::string{key}, std::forward<_Valty>(v)).first;
return it;
}