From 088964324312bf658264b54012fc408da4c950d2 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 9 Mar 2023 12:32:51 +0800 Subject: [PATCH] sstables: mark param of reverse_map() const it does not mutate the map in which the value is looked up, so let's mark map const. also, take this opportunity to use structured binding for better readability. Signed-off-by: Kefu Chai --- sstables/sstables.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 0d79949b2c..e899a26589 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -203,10 +203,10 @@ std::unordered_map -static typename Map::key_type reverse_map(const typename Map::mapped_type& value, Map& map) { - for (auto& pair: map) { - if (pair.second == value) { - return pair.first; +static typename Map::key_type reverse_map(const typename Map::mapped_type& v, const Map& map) { + for (auto& [key, value]: map) { + if (value == v) { + return key; } } throw std::out_of_range("unable to reverse map");