编辑代码

#include <iostream>

template <typename T, typename U>
constexpr bool has_same_type(T, U) {
    return false;
}

template <typename T>
constexpr bool has_same_type(T, T) {
    return true;
}

constexpr auto foo() {
    // return 12345.f;
    return 12345;
}

int main() {
    std::cout << std::boolalpha;

    std::cout << has_same_type(114, 514) << '\n';
    std::cout << has_same_type(114, 5.4) << '\n';
    std::cout << has_same_type("hello", L"hello") << '\n';

    auto n = foo();
    if (has_same_type(n, int{})) {
        std::cout << "Type of n is int\n";
    } else {
        std::cout << "Type of n is not int\n";
    }

    return 0;
}