Skip to content

QuantumGate::MakeCallback

Karel Donk edited this page Jun 15, 2018 · 1 revision

Makes a QuantumGate::Callback object.

Signature

template<typename F>
constexpr auto MakeCallback(F&& function) noexcept(/*condition*/)
template<typename T, typename F>
constexpr auto MakeCallback(T* object, F&& member_function) noexcept;

Parameters

Name Description
function A function pointer or a callable object.
object A pointer to an object.
member_function A member function pointer to invoke on object.

Exceptions

The overload accepting callable objects (lambdas etc.) may throw exceptions if memory allocation or move assignment fails.

Example

int FreeTestFunction(int n) noexcept
{
    return 10;
}

class TestClass
{
public:
    int MemberTestFunction(int n)
    {
        return 10;
    }
};

// Function pointer example
auto cb = MakeCallback(&FreeTestFunction);

// Lambda example
auto cb2 = MakeCallback([](int n){ return 10; });

// Member function pointer example
TestClass t;
auto cb3 = MakeCallback(&t, &TestClass::MemberTestFunction);
Clone this wiki locally