2-4. Using auto with Functions
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2-4. Using auto with Functions相关的知识,希望对你有一定的参考价值。
在C++14中允许使用type deduction用于函数参数和函数返回值
Return Type Deduction in C++11
1 #include <iostream> 2 using namespace std; 3 auto AutoFunctionFromReturn(int parameter) -> int 4 { 5 return parameter; 6 } 7 8 int main() 9 { 10 auto value = AutoFunctionFromReturn(1); 11 cout << value << endl; 12 return 0; 13 }
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(2); cout << value << endl; return 0; }
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(2); cout << value << endl; return 0; }
以上是关于2-4. Using auto with Functions的主要内容,如果未能解决你的问题,请参考以下文章
论文翻译:2018_Artificial Bandwidth Extension with Memory Inclusion using Semi-supervised Stacked Auto-en
Using View and Data API with Meteor
Using AngularJS with .NET MVC 5
TypeORM delete using WHERE with OR operator using Repository