2-4. Using auto with Functions

在C++14中允许使用type deduction用于函数参数和函数返回值

Return Type Deduction in C++11

 #include <iostream>
using namespace std;
auto AutoFunctionFromReturn(int parameter) -> int
{
return parameter;
} int main()
{
auto value = AutoFunctionFromReturn();
cout << value << endl;
return ;
}

Deducing return types for C++11 template functions

#include <iostream>
using namespace std; template <typename T>
auto AutoFunctionFromParameter(T parameter) -> decltype(parameter)
{
return parameter;
} int main()
{
auto value = AutoFunctionFromParameter();
cout << value << endl;
return ;
}

In order to reduce the verbose code

Using auto to Deduce Return Type on a Template Function C++14

#include <iostream>
using namespace std; template <typename T>
auto AutoFunctionFromParameter(T parameter)
{
return parameter;
} int main()
{
auto value = AutoFunctionFromParameter();
cout << value << endl;
return ;
}
上一篇:日本厚劳省对IT技术人员展开确保海外人才调查


下一篇:jetty服务器启动方法总结【备用】