I was using an alias to refer to one of two maps:
map<int, int> & map_alias = use_map_a ? map_a : map_b;
but then changed map_b to use std::greater as its comparator (instead of the default std::less).
As expected, this line of code no longer works because map_alias/map_a/map_b are not all the same type. Is there some simple workaround to allow an alias (or a similar and simple approach) to continue to be used? I would just like the subsequent code to operate generically without needing to know which of the two maps it’s operating on, and without needing to constuct a huge umbrella infrastructure to make it happen.
Using union/tuple/variant/std::any wouldn’t really solve anything, since the map type would still need to be known in order to access the map from those objects.
Limitations: I’m using C++14 and so constexpr cannot be used in the solution. It would be nice not to have to use SFINAE unless necessary. Also I don’t have access to boost.
I’ve spent several hours looking for a solution, so thanks in advance!
1