Made VectorMap find and access functions templates so you don't have to construct the key.

This commit is contained in:
Patrick Wuttke 2025-09-22 21:40:53 +02:00
parent cc20702249
commit 10d9b4c98f

View File

@ -133,7 +133,8 @@ public:
VectorMap& operator=(VectorMap&&) = default;
auto operator<=>(const VectorMap& other) const noexcept = default;
TValue& operator[](const TKey& key)
template<typename TIndex>
TValue& operator[](const TIndex& key)
{
auto it = find(key);
if (it != end())
@ -143,7 +144,8 @@ public:
return emplace(key, TValue()).first->second;
}
const TValue& operator[](const TKey& key) const
template<typename TIndex>
const TValue& operator[](const TIndex& key) const
{
return at(key);
}
@ -251,8 +253,9 @@ public:
return eraseImpl(idx, count);
}
template<typename TSearch>
[[nodiscard]]
iterator find(const TKey& key) MIJIN_NOEXCEPT
iterator find(const TSearch& key) MIJIN_NOEXCEPT
{
for (std::size_t idx = 0; idx < keys_.size(); ++idx)
{
@ -264,8 +267,9 @@ public:
return end();
}
template<typename TSearch>
[[nodiscard]]
const_iterator find(const TKey& key) const MIJIN_NOEXCEPT
const_iterator find(const TSearch& key) const MIJIN_NOEXCEPT
{
for (std::size_t idx = 0; idx < keys_.size(); ++idx)
{