I am currently implementing a class that is a three-way map, meaning each "index" has three keys and one can retrieve each. The function get is defined as:
template<typename returnType, typename getType>
returnType get(getType getVal) {
    if (typeid(returnType) == typeid(getType)) {
        return getVal;
    }
    
    // Here the appropriate value is gotten. Not important for this.
    
    // This is returned just in-case nothing is found.
    return *new returnType;
}
This doesn't compile, because getType is not always equal to returnType, which is guaranteed by my check. Is there a way to make this compile, because the getting process is quite expensive. I've tried to just do return returnType(getVal);, which only works if returnType has a constructor for getType.
Solutions I could imagine but didn't manage to pull of:
- template specialization
- disable type-checking (similar to rust's unsafe)
P.S: I know this optimisation doesn't make a lot of sense, still would like to know if it's possible to compile.
 
    