I am writing a C ++ 11 template function void foo(T, U)using two parameters:
The first parameter, which can be either type A1 or type B1. If the first parameter is of type A1, the second parameter is of type A2; If the first parameter is of type B1, the second parameter is of type B2;
Since the second parameter depends on the first, is there a way to write this function that requires only one template parameter?
Something along the line
template class <T>
void foo(T t, std::conditional<A1* tmp = dynamic_cast<T*>(&t), A2, B2>::type);
may work, but its ugly and needs RTTI.
Is there a good way to achieve this?
source
share