-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Open
Description
Inspired by: https://blog.petrzemek.net/2017/01/17/pros-and-cons-of-alternative-function-syntax-in-cpp/
- When using
decltype
, as then the return type is free to use parameter names too. If this is thought to be too strict, then use trailing return when thedecltype
expression would otherwise have to construct a type instance (e.g. usingstd::declval
) when there is also a function parameter of that type which could be used instead (which would be easier to read). - When defining a method outside of the class declaration, and the return type is a type alias defined inside the same class as the method. This avoids repeating
class_name::
for the return type.- Similarly when
decltype
is used for a class method return type with an expression usingclass_name::some_member
.
- Similarly when
- When the function returns a function pointer. This is much easier to read.
More generally, it would be good to recommend trailing return whenever the return type has more than one alpha-numeric token, so the function name is easy to read quickly. (This would obviate the need for the first two rules above).
Metadata
Metadata
Assignees
Labels
No labels