Do I need to put constexpr after else-if?
问题 Inspired by this answer, I tried to copy and paste (and add testing in main() ) this code: template<typename T> std::tuple<int, double> foo(T a) { if constexpr (std::is_same_v<int, T>) return {a, 0.0}; else if (std::is_same_v<double, T>) return {0, a}; else return {0, 0.0}; } int main() { auto [x, y] = foo(""); std::cout << x << " " << y; } This is very straightforward - if T is deduced as int , we want to return a tuple of [a, 0.0] . If T is deduced as double , we want to return a tuple of