I have a few disjoint maps which map unique types to strings. For example:
enum class Colors {RED, GREEN};
enum class Days {MON, SUN};
std::map <Colors, std::string> map1{
{Colors::RED, "red"},
{Colors::GREEN, "green"},
};
std::map <Days, std::string> map2{
{Days::MON, "mon"},
{Days::SUN, "sun"},
};
Given a key, I want to be able to extract its value transparently from the corresponding map (there is exactly one map for a type).
I considered a wrapper function like so
template <typename T>
auto extractValue(T k){
// Somehow use type T to switch maps and return value corresponding to k
}
I'm however not sure how/if this can be achieved. If this is not possible, what could be an alternate approach where I can exploit the fact that there is exactly one map per type.
I'm using C++20.
Edit: I can achieve this by writing overloads of extractValue
for each type, but I'm looking for a more "generic" approach.