summaryrefslogtreecommitdiff
path: root/src/utils/cpp/back_map.hpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2025-02-18 12:57:44 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2025-02-19 17:50:30 +0100
commite5de23f9abefaf97374564b6739dd66b5d9aa570 (patch)
tree6a738d81b6d93778b4cf1a58b12588e921f3701e /src/utils/cpp/back_map.hpp
parent8ab573ef1c624e2ed81b2032178c25451176d2f1 (diff)
downloadjustbuild-e5de23f9abefaf97374564b6739dd66b5d9aa570.tar.gz
BackMap: Implement GetReferences
Diffstat (limited to 'src/utils/cpp/back_map.hpp')
-rw-r--r--src/utils/cpp/back_map.hpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils/cpp/back_map.hpp b/src/utils/cpp/back_map.hpp
index debe5bac..ab41346e 100644
--- a/src/utils/cpp/back_map.hpp
+++ b/src/utils/cpp/back_map.hpp
@@ -143,6 +143,20 @@ class BackMap final {
return result;
}
+ /// \brief Obtain the set of values corresponding to given keys. If a key
+ /// isn't known to the container, it is ignored. Copy free.
+ [[nodiscard]] auto GetReferences(std::unordered_set<TKey> const& keys)
+ const noexcept -> std::unordered_set<gsl::not_null<TValue const*>> {
+ std::unordered_set<gsl::not_null<TValue const*>> result;
+ result.reserve(keys.size());
+ for (auto const& key : keys) {
+ if (auto value = GetReference(key)) {
+ result.emplace(*std::move(value));
+ }
+ }
+ return result;
+ }
+
using Iterable = std::unordered_map<gsl::not_null<TKey const*>,
gsl::not_null<TValue const*>>;