bl**********@gmail.com wrote:
I want to accomplish the following
void foo(const T &v1, const T &v2)
{
if(v1&v2 is of type double)
?? Is foo supposed to be a template?
double alpha=1.0;
else if (v1&v2 is of type complex double)
complex double alpha=(1.0,1.0);
Did you mean std::complex<double>?
bar(v1,v2,alpha);
}
What if v1 and v2 are of neither of those 2 types? Anyway, maybe you are
searching for specialization:
template <typename T>
void foo(const T &v1, const T &v2)
{
//whatever you want the default to be
}
template<>
void foo(const double &v1, const double &v2)
{
const double alpha(1.0);
bar(v1,v2,alpha);
}
template<>
void foo(const std::complex<double> &v1, const std::complex<double> &v2)
{
const std::complex<double> alpha(1.0,1.0);
bar(v1,v2,alpha);
}