Skip to content

Commit c64b23b

Browse files
N-Dekkerdzenanz
authored andcommitted
ENH: Add "Trailing Return Types" section
Adds a guideline in accordance with commit InsightSoftwareConsortium/ITK@c54ad67 "COMP: Use trailing return type instead of typename + dependent type" Discussed at pull request InsightSoftwareConsortium/ITK#2780 "Workaround VS2017 compile errors using-declarations"
1 parent d833447 commit c64b23b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,47 @@ \section{Increment/decrement Operators}
30033003
\normalsize
30043004
30053005
3006+
\section{Trailing Return Types}
3007+
\label{sec:TrailingReturnTypes}
3008+
3009+
Whenever choosing between a trailing return type (as introduced with C++11) and
3010+
the old form of having the return type before the function name (as was already
3011+
supported by C++98), prefer the form that is the shortest, and the simplest.
3012+
3013+
In the following example, the old form is preferred over a trailing return type:
3014+
\small
3015+
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
3016+
// Preferred:
3017+
template <typename T1, typename T2>
3018+
bool
3019+
AlmostEquals(T1 x1, T2 x2)
3020+
3021+
// Rather than:
3022+
template <typename T1, typename T2>
3023+
auto
3024+
AlmostEquals(T1 x1, T2 x2) -> bool
3025+
\end{minted}
3026+
\normalsize
3027+
3028+
In the following example, a trailing return type is preferred over the old form:
3029+
3030+
\small
3031+
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
3032+
3033+
// Preferred:
3034+
template <typename TValue, unsigned int VLength>
3035+
auto
3036+
FixedArray<TValue, VLength>::Size() const -> SizeType
3037+
3038+
// Rather than:
3039+
template <typename TValue, unsigned int VLength>
3040+
typename FixedArray<TValue, VLength>::SizeType
3041+
FixedArray<TValue, VLength>::Size() const
3042+
3043+
\end{minted}
3044+
\normalsize
3045+
3046+
30063047
\section{Empty Arguments in Methods}
30073048
\label{sec:EmptyArgumentInMethods}
30083049

0 commit comments

Comments
 (0)