mirror of
https://github.com/transmission/transmission.git
synced 2026-02-15 07:26:49 +00:00
feat: add tr_variant::Map methods (#7910)
* feat: add tr_variant::Map::contains() * feat: add tr_variant::Map::replace_key() * fixup! feat: add tr_variant::Map::replace_key() fix readability-braces-around-statements * fixup! feat: add tr_variant::Map::contains() readability-container-contains
This commit is contained in:
@@ -99,6 +99,11 @@ public:
|
||||
return Vector::const_iterator{ const_cast<Map*>(this)->find(key) };
|
||||
}
|
||||
|
||||
[[nodiscard]] auto contains(tr_quark const key) const noexcept
|
||||
{
|
||||
return find(key) != end(); // NOLINT(readability-container-contains)
|
||||
}
|
||||
|
||||
[[nodiscard]] TR_CONSTEXPR20 auto find(std::initializer_list<tr_quark> keys) noexcept
|
||||
{
|
||||
auto constexpr Predicate = [](auto const& item, tr_quark key)
|
||||
@@ -139,6 +144,23 @@ public:
|
||||
return 0U;
|
||||
}
|
||||
|
||||
bool replace_key(tr_quark const old_key, tr_quark const new_key)
|
||||
{
|
||||
if (contains(new_key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto iter = find(old_key);
|
||||
if (iter == end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
iter->first = new_key;
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] tr_variant& operator[](tr_quark const& key)
|
||||
{
|
||||
if (auto const iter = find(key); iter != end())
|
||||
|
||||
Reference in New Issue
Block a user