Skip to content

Commit

Permalink
[clang-tidy][docs] Use std::optional instead of absl::optional in exa…
Browse files Browse the repository at this point in the history
…mples

The standard type is vastly more popular than the Abseil polyfill, so it
makes more sense to use it in documentation, even though the checker
actually understands both (and that fact is documented already).
  • Loading branch information
gribozavr committed Jun 11, 2022
1 parent 7dee646 commit 65299c9
Showing 1 changed file with 12 additions and 12 deletions.
Expand Up @@ -42,7 +42,7 @@ existence check:

.. code-block:: c++

void f(absl::optional<int> opt) {
void f(std::optional<int> opt) {
use(*opt); // unsafe: it is unclear whether `opt` has a value.
}
Expand All @@ -54,7 +54,7 @@ branches of the code. For example:

.. code-block:: c++

void f(absl::optional<int> opt) {
void f(std::optional<int> opt) {
if (opt.has_value()) {
} else {
use(opt.value()); // unsafe: it is clear that `opt` does *not* have a value.
Expand Down Expand Up @@ -99,11 +99,11 @@ optional has a value. For example:

.. code-block:: c++

void g(absl::optional<int> opt) {
void g(std::optional<int> opt) {
use(*opt); // unsafe: it is unclear whether `opt` has a value.
}
void f(absl::optional<int> opt) {
void f(std::optional<int> opt) {
if (opt.has_value()) {
g(opt);
}
Expand All @@ -121,7 +121,7 @@ example:

.. code-block:: c++

void f(absl::optional<int> opt) {
void f(std::optional<int> opt) {
if (opt.has_value()) {
use(*opt);
}
Expand All @@ -137,9 +137,9 @@ have a value. For example:

.. code-block:: c++

void f(absl::optional<int> opt1) {
void f(std::optional<int> opt1) {
if (opt1.has_value()) {
absl::optional<int> opt2 = opt1;
std::optional<int> opt2 = opt1;
use(*opt2);
}
}
Expand All @@ -154,7 +154,7 @@ a value. For example:

.. code-block:: c++

void f(absl::optional<int> opt) {
void f(std::optional<int> opt) {
DCHECK(opt.has_value());
use(*opt);
}
Expand All @@ -168,7 +168,7 @@ paths that lead to an access. For example:

.. code-block:: c++

void f(absl::optional<int> opt) {
void f(std::optional<int> opt) {
bool safe = false;
if (opt.has_value() && SomeOtherCondition()) {
safe = true;
Expand Down Expand Up @@ -223,7 +223,7 @@ check the optional again in the local scope of the callee. For example:
use(val);
}

void f(absl::optional<int> opt) {
void f(std::optional<int> opt) {
if (opt.has_value()) {
g(*opt);
}
Expand All @@ -234,7 +234,7 @@ and
.. code-block:: c++

struct S {
absl::optional<int> opt;
std::optional<int> opt;
int x;
};

Expand All @@ -260,7 +260,7 @@ The check is aware of aliases of optional types that are created via

.. code-block:: c++

using OptionalInt = absl::optional<int>;
using OptionalInt = std::optional<int>;

void f(OptionalInt opt) {
use(opt.value()); // unsafe: it is unclear whether `opt` has a value.
Expand Down

0 comments on commit 65299c9

Please sign in to comment.