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

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 24 12:00:40 PDT 2019


labath added a comment.

In D69230#1720246 <https://reviews.llvm.org/D69230#1720246>, @dblaikie wrote:

> In D69230#1720048 <https://reviews.llvm.org/D69230#1720048>, @labath wrote:
>
> > That said, I think you have convinced me that having different optional representations for a single type is not a good idea. It's probably better to use some form of a "strong" typedef to achieve that instead.
>
>
> I've not followed this part of the thread properly - could you/someone rephrase the concerns here?


Sure. lldb currently has types like lldb::pid_t, and uses identifiers like LLDB_INVALID_PID for the "None" value. I wanted to define pid_t as something like `Optional<some_integer_type, PIDInfo>`, where PIDInfo would specify what is the representation of an "invalid" pid. The reason I abandoned this idea was that this arrangement makes it impossible to represent (in the type system) a pid which is always valid. I now think that it would be better (at least for this use case) to have `pid_t be a "strong" typedef of the integer type. At that point you can specify an "invalid" value for this type even without a separate Optional template argument...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69230





More information about the lldb-commits mailing list