Home >Backend Development >C++ >Should Trailing Return Types Be the Standard in New C 11 Code?
Trailing Return Type Syntax: Should It Be the Norm in New C 11 Programs?
C 11 introduced a new function syntax that allows specifying the return type at the end of the parameter list:
auto func_name(int x, int y) -> int;
While this syntax is supported, its adoption has been limited. The question arises whether it should be the default style in new C 11 programs.
Where Trailing Return Types Are Required
Certain situations necessitate the use of trailing return types, such as:
Advantages of Trailing Return Types
Beyond these requirements, trailing return types offer several advantages:
Conclusion
While trailing return types have certain advantages, they are not currently widely adopted. However, their use in specific cases and their potential for enhancing readability suggest that they may become more prevalent in the future. For new C 11 programs, it is recommended to consider adopting trailing return types where appropriate to improve code aesthetics and maintain consistency.
The above is the detailed content of Should Trailing Return Types Be the Standard in New C 11 Code?. For more information, please follow other related articles on the PHP Chinese website!