refactor: use new `tr_variant` API in remote

This commit is contained in:
Yat Ho 2024-04-12 17:09:04 +08:00 committed by Charles Kerr
parent c3d686c78f
commit 94e747043a
3 changed files with 1485 additions and 1351 deletions

View File

@ -73,8 +73,7 @@ template<typename T>
if (auto* const map = var != nullptr ? var->get_if<tr_variant::MapIndex>() : nullptr; map != nullptr)
{
map->erase(key);
return &map->try_emplace(key, std::forward<T>(val)).first;
return &map->insert_or_assign(key, std::forward<T>(val)).first;
}
return {};

View File

@ -148,8 +148,26 @@ public:
return { vec_.emplace_back(key, tr_variant{ std::forward<Val>(val) }).second, true };
}
template<typename Val>
std::pair<tr_variant&, bool> insert_or_assign(tr_quark const key, Val&& val)
{
auto res = try_emplace(key, std::forward<Val>(val));
if (!res.second)
{
res.first = std::forward<Val>(val);
}
return res;
}
// --- custom functions
template<typename Type>
[[nodiscard]] TR_CONSTEXPR20 auto find_if(tr_quark const key) noexcept
{
auto const iter = find(key);
return iter != end() ? iter->second.get_if<Type>() : nullptr;
}
template<typename Type>
[[nodiscard]] TR_CONSTEXPR20 auto find_if(tr_quark const key) const noexcept
{

File diff suppressed because it is too large Load Diff