Function

Contents

Function#

template<typename F>
FunctionHandler<F> YR::Function(F f)#

Constructs a FunctionHandler for a given function.

This function template creates a FunctionHandler object for a specified static function. The FunctionHandler object can then be used to execute the function and set various options for the function call, such as resource allocation.

#include "yr/yr.h"

int PlusOne(int x)
{
    return x + 1;
}

YR_INVOKE(PlusOne)

int main()
{
    YR::Config conf;
    YR::Init(conf);

    std::vector<YR::ObjectRef<int>> n2;
    int k = 1;
    for (int i = 0; i < k; i++) {
        auto r2 = YR::Function(PlusOne).Invoke(2);
        n2.emplace_back(r2);
    }
    for (int i = 0; i < k; i++) {
        auto integer = *YR::Get(n2[i]);
        printf("%d :%d\n", i, integer);
    }

    YR::Finalize();
    return 0;
}

Template Parameters:

F – The type of the function to be executed.

Parameters:

f – The static function to be called.

Throws:

Exception – If the function has not been registered using the YR_INVOKE macro, an exception will be thrown.

Returns:

FunctionHandler<F>: A FunctionHandler object that provides methods to execute the function and set options for the function call.