template <typename IN,typename OUT,bool isVector>
OUT foo(IN x){
if (isVector){
return x[0];
} else {
return x;
}
}
After asking this question I wrongly assumed, that the above code could compile for e.g.
foo<double,double,false>;
as well as
foo<std::vector<double>,double,true>;
However, even if one of the if-branches never gets executed, it is checked for correctness and thus the above does not compile. How can I fix it?
The code above is a simplified, but I dont know how to fix it, as function templates cannot have partial specialization...
Copyright Notice:Content Author:「463035818_is_not_a_number」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33465830/how-to-fix-this-template