[PATCH] D112281: WIP: Support: Add Expected<T>::emplaceInto()

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 21 16:13:08 PDT 2021


dexonsmith created this revision.
dexonsmith added reviewers: lhames, dblaikie.
dexonsmith requested review of this revision.
Herald added a project: LLVM.

Expected<T>::emplaceInto() takes as an out parameter any
`Optional<OtherT>`, with `OtherT` constructible from `T&&`. It either
calls Optional<OtherT>::emplace() with the stored value, or calls
Optional<OtherT>::reset() if none, before returning takeError().

emplaceInto() is similar to Expected<T>::moveInto() / https://reviews.llvm.org/D112278, but works with an
Optional that contains a construct-only type that `T` can be moved into.

  Optional<ConstructOnly> P;
  if (Error E = makeConstructOnly().emplaceInto(P))
    return E;

I'm not sure this is really useful enough -- construct-only types are a
real thing, but it's not often possible to move-construct them. It's
unlikely that an `Expected` would contain one. Perhaps this is too
specific a use case?

Also, would this be better as a free function? (It probably doesn't make
sense to add overloads to `Expected<T>` for arbitrary box types... but
as a free function you could easily extend without modifying Expected.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112281

Files:
  llvm/include/llvm/Support/Error.h
  llvm/unittests/Support/ErrorTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112281.381424.patch
Type: text/x-patch
Size: 3125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211021/63552487/attachment.bin>


More information about the llvm-commits mailing list