Often times you expect an operation to succeed, and it's cumbersome and impacts readability to constantly be checking errors which you assume are going to succeed. It's even worse with Expected<T>, because you have to write something like:
auto ExpectedFoo = getFoo(); if (!ExpectedFoo) return ExpectedFoo.takeError(); auto &Foo = *ExpectedFoo;
which is 4 lines of code for something that should take 1 (assuming, again, that you have special knowledge which would allow you to know in advance it will succeed). You can reduce it to 3 lines by doing this:
auto ExpectedFoo = getFoo(); consumeError(ExpectedFoo.takeError()); auto &Foo = *ExpectedFoo;
But now if there ever actually *is* an error, it's dropped on the floor. So we could add an assert, but now we're back to 4 lines.
It would be nice to have a function which asserts if there is an error, so we get notified in debug builds, but continues on as if nothing ever happened in release. We already have a similar construct which is ExitOnErr, but we want a similar construct that doesn't exit and still allows us to extract the value and consume the error in a single line. With this patch we can write:
expectSuccess(doSomething()); // returns an Error auto Value = expectSuccess(getSomething()); // returns an Expected<T>
and it just works, with 1 line.