写C++模板函数的两种形式
#include <iostream>
template <typename T>
auto f1(const T& x) {
std::cout << x << std::endl;
};
auto f2 = [](const auto& x){
std::cout << x << std::endl;
};
int main(int argc, char** argv)
{
int x1 = 1;
double x2 = 1.0;
char x3 = '1';
std::string x4 = "1";
f1(x1);
f1(x2);
f1(x3);
f1(x4);
f2(x1);
f2(x2);
f2(x3);
f2(x4);
}

浙公网安备 33010602011771号