-
Notifications
You must be signed in to change notification settings - Fork 23
QuantumGate::Result::Succeeded
Karel Donk edited this page Sep 5, 2018
·
5 revisions
Returns whether the operation succeeded or executes a lambda function in case the operation succeeded depending on the overload used.
constexpr const bool Succeeded() const noexcept;
template<typename F>
void Succeeded(F&& function) const;
Name | Description |
---|---|
function |
The function to execute when succeeded. This function should accept either one parameter or none. When the function accepts one parameter it should be a reference to a QuantumGate::Result object. |
The overload returning a bool
will return true
when the operation succeeded and thus either contains no error and has a value (for results containing a value), and false
when it contains an error and no value.
Result<int> FunctionReturningAResult()
{
return 5;
}
// First example
auto result = FunctionReturningAResult();
if (result.Succeeded())
{
// Succeeded
}
// Second example executes a lambda when succeeded
if (FunctionReturningAResult().Succeeded([]()
{
// Succeeded
});
// Third example executes a lambda when succeeded
// passing in a reference to the result
if (FunctionReturningAResult().Succeeded([](auto& result)
{
std::cout << result;
});