[PATCH] D69230: RFC: specialized Optional<T> for T that can represent its own invalid state

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 23:43:56 PDT 2019


dblaikie added a comment.

In D69230#1717675 <https://reviews.llvm.org/D69230#1717675>, @serge-sans-paille wrote:

> On a personal note, as much as I like the idea (and I really do like it), I'd rather have llvm::optional sticking to std::optional interface.


(short-ish reply, while busy with the dev meeting)
Yep, that's about where I am - I think llvm::Optional should move towards the std::optional API. And I don't think maintaining a separate/additional type for this functionality is worth the complexity of having a distinct type compared to something more and more people will be readily familiar with (std::optional).

But, like serge, I really do like the idea of exposing one or more "secret" States from types to use spare bits, padding-ish bits, etc, for DenseMap, PointerIntPair/PointerUnion, etc. (be nice to unify these extra state bits, even, if possible, across all these types so you could potentially compose them - if you've got 3 spare bits in your underlying representation (say, an aligned pointer) perhaps you could have a DenseSet<Optional<T*>> with elements that are only sizeof(T*) for instance)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69230/new/

https://reviews.llvm.org/D69230





More information about the llvm-commits mailing list