[PATCH] Improvements to llvm::Optional

Jordan Rose jordan_rose at apple.com
Wed Sep 24 12:16:05 PDT 2014


Hi, all. For some projects, we've been working with a modified version of llvm::Optional<T> for some time now, many of them inspired by std::experimental::optional in the "Library Fundamentals" C++ TS. I'd like to see how everyone feels about pushing these changes back into master:

- Move assignment operator.
- getValueOr, which takes an argument convertible to T and returns the Optional's value, if it has one, or a T constructed from the argument if not
- A typedef for T under the name 'value_type'.
- For compilers with variadic templates, an "emplace" method for in-place initialization of non-moveable types.
- Implicit conversion from any type convertible to T. We used to almost have this everywhere via the operator=(const T &) overload, but that didn't include construction or (for compilers with variadic templates) multi-argument initialization. This is not a feature of std::experimental::optional, but we've found it useful.

The additions require no changes to LLVM or Clang, except the OptionalTests suite. There is one downside here: assignment of a T&& now requires an extra move, because otherwise we'd have ambiguous overloads for assignment of a type convertible to T. Is anyone depending on that?

Jordan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140924/e1c3200f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Optional.patch
Type: application/octet-stream
Size: 10893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140924/e1c3200f/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140924/e1c3200f/attachment-0001.html>


More information about the llvm-commits mailing list