Skip to content

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.

Signature

constexpr const bool Succeeded() const noexcept;
template<typename F>
void Succeeded(F&& function) const;

Parameters

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.

Return values

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.

Example

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;
});
Clone this wiki locally