Skip to content

Commit

Permalink
morestl: add example slide for std::optional
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Lekshmanan <abhishek.lekshmanan@cern.ch>
  • Loading branch information
theanalyst committed Dec 16, 2021
1 parent b9dd9e7 commit 004cfc9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions talk/morelanguage/morestl.tex
Expand Up @@ -25,6 +25,26 @@ \subsection{More STL}
\end{block}
\end{frame}

\begin{frame}[fragile]
\frametitlecpp[17]{std::optional}
\scriptsize
\begin{cppcode}
std::optional<Phone> parse\_phone(std::string\_view in)
{
if (is\_valid\_phone(in)) {
return std::optional<Phone>(in);
}
return std::nullopt; // {} also default constructs to nullopt
}

...
if (auto v = parse\_phone(get\_input());
v.is\_valid()) {
process\_phone(v.value());
}
\end{cppcode}
\end{frame}

\begin{frame}[fragile]
\frametitlecpp[11]{non-member begin and end}
\begin{alertblock}{The problem in \cpp98}
Expand Down

0 comments on commit 004cfc9

Please sign in to comment.