Home:ALL Converter>How to fix this template:

How to fix this template:

Ask Time:2015-11-02T02:45:41         Author:463035818_is_not_a_number

Json Formatter

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...

Author:463035818_is_not_a_number,eproduced 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
yy