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; +} +