[PATCH] D85072: [ADT] Add getAsOr to Optional

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 11:43:19 PDT 2020


dblaikie added a comment.

In D85072#2193251 <https://reviews.llvm.org/D85072#2193251>, @njames93 wrote:

> In D85072#2191557 <https://reviews.llvm.org/D85072#2191557>, @dblaikie wrote:>
>
>> Hmm, I'm not so sure - getValueOr, for instance, is in std::optional. (value_or)
>>
>> You're right that 'map', for instance, is not in std::optional, though. That and maybe the "create" function are the non-std::optional API?
>
> And `getPointer`

Ah, right you are - I was thinking std::optional had "get()" like std::unique_ptr, but I must've got them jumbled up.

>> I think if this new function was a non-member, it'd probably tidier - wouldn't need an rvalue and non-rvalue overload, as it could use std::forward on both arguments.
>
> non-member could work I guess, and could be adapted for other cases, std::optional or pointers spring to mind.

Yep. (also, wouldn't mind if the test was a bit more narrow - if possible, not using non-trivial standard library types - using explicitly written types (not necessarily written just for the test - there are other common utility/stub/mock types in this file and other test files that can be generalized a bit and reused, etc) to test certain features - narrows the scope a bit so the test isn't dependent on too much else)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85072



More information about the llvm-commits mailing list