Optional value casting
----------------------
When your types are not constructible from ``nullptr`` or there isn't a simple
-way to tell when an object is invalid, you may want to use ``llvm::Optional``.
+way to tell when an object is invalid, you may want to use ``std::optional``.
In those cases, you probably want something like this:
.. code-block:: c++
.. code-block:: c++
SomeValue someVal = ...;
- Optional<AnotherValue> valOr = dyn_cast<AnotherValue>(someVal);
+ std::optional<AnotherValue> valOr = dyn_cast<AnotherValue>(someVal);
With the ``_if_present`` variants, you can even do optional chaining like this:
.. code-block:: c++
- Optional<SomeValue> someVal = ...;
- Optional<AnotherValue> valOr = dyn_cast_if_present<AnotherValue>(someVal);
+ std::optional<SomeValue> someVal = ...;
+ std::optional<AnotherValue> valOr = dyn_cast_if_present<AnotherValue>(someVal);
-and ``valOr`` will be ``None`` if either ``someVal`` cannot be converted *or*
-if ``someVal`` was also ``None``.
+and ``valOr`` will be ``std::nullopt`` if either ``someVal`` cannot be converted *or*
+if ``someVal`` was also ``std::nullopt``.
/// This method looks up the specified field and returns its value as a
/// string, throwing an exception if the value is not a string and
- /// llvm::Optional() if the field does not exist.
+ /// std::nullopt if the field does not exist.
std::optional<StringRef> getValueAsOptionalString(StringRef FieldName) const;
/// This method looks up the specified field and returns its value as a
// function call or any of the memory intrinsics, we check whether this
// instruction is prior to CoroBegin. To answer question 3, we track the offsets
// of all aliases created for the alloca prior to CoroBegin but used after
-// CoroBegin. llvm::Optional is used to be able to represent the case when the
+// CoroBegin. std::optional is used to be able to represent the case when the
// offset is unknown (e.g. when you have a PHINode that takes in different
// offset values). We cannot handle unknown offsets and will assert. This is the
// potential issue left out. An ideal solution would likely require a