[PATCH] D112281: WIP: Support: Add Expected<T>::emplaceInto()
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 22 13:04:54 PDT 2021
dexonsmith abandoned this revision.
dexonsmith added a comment.
In D112281#3079734 <https://reviews.llvm.org/D112281#3079734>, @dblaikie wrote:
> Yeah, similarly mixed feelings.
>
> Might be at some point we would put up with using a small selection of macros (google's done something similar, begrudgingly, to handle absl::Status) to make it possible to actually create a local variable with initialization from an Expected result - I think that requires statement expressions or other shenanigans to make that work, though, which is also annoying, on top of the macros.
A couple of other ideas that are implementable, but I'm not sure are really better than just doing the boilerplate:
struct ChallengingType {
ChallengingType(std::string S, bool Flag, int I, ...);
};
Expected<std::string> makeString();
Expected<std::string> makeInt();
void f1(bool Flag) {
Optional<ChallengingType> CT;
// Filters arguments for `Expected<T>`, joining all errors.
// Calls `emplace()` with moved values if there are none.
if (Error E = CT.emplaceWithExpected(makeString(), Flag, makeInt(), ...))
return E;
// As above, but generalized to types other than Optional.
// Returns Expected<X> if object returns X.
if (Error E = emplaceWithExpected(CT, makeString(), Flag, makeInt(), ...))
return E;
// As above, but instead of filtering for Expected, filters for a temporary
// lambda returned by `delayExpected()`.
if (Error E = emplaceWithDelayedExpected(
CT,
delayExpected([&]() {return makeString();}),
Flag,
delayExpected([&]() {return makeInt();}),
...))
return E;
// As above, but call any function, not just emplace.
if (Error E = callWithDelayedExpected(
delayExpected([&]() {return makeString();}),
Flag,
delayExpected([&]() {return makeInt();}),
...,
[&CT](std::string S, bool Flag, int I, ...) {
CT.emplace(std::move(S), Flag, I, ...);
}))
return E;
// ... other code ...
}
Anyway, I'll abandon this.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112281/new/
https://reviews.llvm.org/D112281
More information about the llvm-commits
mailing list