.. 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.
}
.. 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.
.. 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);
}
.. code-block:: c++
- void f(absl::optional<int> opt) {
+ void f(std::optional<int> opt) {
if (opt.has_value()) {
use(*opt);
}
.. 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);
}
}
.. code-block:: c++
- void f(absl::optional<int> opt) {
+ void f(std::optional<int> opt) {
DCHECK(opt.has_value());
use(*opt);
}
.. 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;
use(val);
}
- void f(absl::optional<int> opt) {
+ void f(std::optional<int> opt) {
if (opt.has_value()) {
g(*opt);
}
.. code-block:: c++
struct S {
- absl::optional<int> opt;
+ std::optional<int> opt;
int x;
};
.. 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.