Skip to content

Commit

Permalink
ENH: Add "Trailing Return Types" section
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
N-Dekker authored and dzenanz committed Jan 18, 2022
1 parent d833447 commit c64b23b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,47 @@ \section{Increment/decrement Operators}
\normalsize
\section{Trailing Return Types}
\label{sec:TrailingReturnTypes}
Whenever choosing between a trailing return type (as introduced with C++11) and
the old form of having the return type before the function name (as was already
supported by C++98), prefer the form that is the shortest, and the simplest.
In the following example, the old form is preferred over a trailing return type:
\small
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
// Preferred:
template <typename T1, typename T2>
bool
AlmostEquals(T1 x1, T2 x2)
// Rather than:
template <typename T1, typename T2>
auto
AlmostEquals(T1 x1, T2 x2) -> bool
\end{minted}
\normalsize
In the following example, a trailing return type is preferred over the old form:
\small
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
// Preferred:
template <typename TValue, unsigned int VLength>
auto
FixedArray<TValue, VLength>::Size() const -> SizeType
// Rather than:
template <typename TValue, unsigned int VLength>
typename FixedArray<TValue, VLength>::SizeType
FixedArray<TValue, VLength>::Size() const
\end{minted}
\normalsize
\section{Empty Arguments in Methods}
\label{sec:EmptyArgumentInMethods}
Expand Down

0 comments on commit c64b23b

Please sign in to comment.