summaryrefslogtreecommitdiff
path: root/doc/qtcreatordev
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2023-02-16 14:16:47 +0100
committerEike Ziller <eike.ziller@qt.io>2023-02-23 13:33:53 +0000
commit143835aea8ab25d4ceb9d1413c16de97f664f961 (patch)
tree72de9e587fe898311a5ba23ee3659b65a11caa33 /doc/qtcreatordev
parentc2266981c91825838a0d5fe9ec28267c2ede42c1 (diff)
downloadqt-creator-143835aea8ab25d4ceb9d1413c16de97f664f961.tar.gz
Coding style: Avoid optional::value()
Change-Id: Ic4769c6f9f016415e01ca5526f6730bc93c6ea81 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'doc/qtcreatordev')
-rw-r--r--doc/qtcreatordev/src/coding-style.qdoc23
1 files changed, 23 insertions, 0 deletions
diff --git a/doc/qtcreatordev/src/coding-style.qdoc b/doc/qtcreatordev/src/coding-style.qdoc
index 02636e3ab5..22da9cca0c 100644
--- a/doc/qtcreatordev/src/coding-style.qdoc
+++ b/doc/qtcreatordev/src/coding-style.qdoc
@@ -899,6 +899,29 @@
container is const or unshared, use \c{std::cref()} to ensure that the container
is not unnecessarily detached.
+ \section3 std::optional
+
+ Avoid the throwing function \c{value()}. Check the availability of the value first, and then use
+ the non-throwing functions for accessing values, like \c{operator*} and \c{operator->}.
+ In very simple cases, you can also use \c{value_or()}.
+
+ \code
+
+ if (optionalThing) {
+ val = optionalThing->member;
+ other = doSomething(*optionalThing);
+ }
+
+ -NOT-
+
+ if (optionalThing) {
+ val = optionalThing.value().member;
+ other = doSomething(optionalThing.value());
+ }
+
+ \endcode
+
+
\section2 Using QObject
\list