Why is this code invalid without constexpr:
template<typename ...Tpack>
auto CalculateSum(Tpack ...pack)
{
if constexpr (sizeof...(Tpack) > 0)
return (pack + ...);
else
return 0;
}
int main()
{
std::cout << CalculateSum(2, 3, 4, 5, 7.5, 6) << '\n';
}
whereas if there are only int in the arguments, it gets valid.
Compiler says: 'auto' in return type deduced as 'int' here but deduced as 'double' in earlier return statement
But how does constexpr resolves?