I have a working bidirectional map (one-to-one mapping) class as follows:
template <typename T1, typename T2>
class BiMap
{
public:
void insert(const T1& a, const T2& b);
private:
std::map<T1, T2*> map1_;
std::map<T2, T1*> map2_;
};
I have been able to implement the insert function. Now I want to implement a retrieve function such that if user passes value of type T1 say t1, it'll return *map1_[t1] and similarly if they pass value of type T2 say t2, it'll return *map2_[t2]. It is guaranteed that type T1 will not be the same as type T2 so how can I make it return a value by checking it's type?