From 185fcf5a7d3748deebf8a042458e86914d6f78de Mon Sep 17 00:00:00 2001 From: lovelyyoung <1002639516@qq.com> Date: Sat, 20 Jun 2020 11:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=80=BC=E6=89=BE=E9=94=AE?= =?UTF-8?q?=E5=80=BC=E6=A8=A1=E6=9D=BF=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- huagao/MapFinder.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 huagao/MapFinder.h diff --git a/huagao/MapFinder.h b/huagao/MapFinder.h new file mode 100644 index 00000000..a051078d --- /dev/null +++ b/huagao/MapFinder.h @@ -0,0 +1,16 @@ +#pragma once +#include +template +auto get_map_key_by_value(const MapType& input_map, const decltype(input_map.begin()->second)& mapped_value) -> decltype(input_map.begin()->first) +{ + auto iter = std::find_if(input_map.begin(), input_map.end(), [mapped_value](const auto& item) { + return (item.second == mapped_value); + }); + + if (iter == input_map.end()) + { + return decltype(input_map.begin()->first)(); + } + return iter->first; +} +