A PackedFunc wrapper to provide typed function signature. It is backed by a PackedFunc internally.
More...
#include <packed_func.h>
template<typename R, typename... Args>
class tvm::runtime::TypedPackedFunc< R(Args...)>
A PackedFunc wrapper to provide typed function signature. It is backed by a PackedFunc internally.
TypedPackedFunc enables compile time type checking. TypedPackedFunc works with the runtime system:
Developers should prefer TypedPackedFunc over PackedFunc in C++ code as it enables compile time checking. We can construct a TypedPackedFunc from a lambda function with the same signature.
auto addone = [](int x)->int {
return x + 1;
};
int y = ftyped(1);
const PackedFunc & packed() const
Definition: packed_func.h:359
TypedPackedFunc()
default constructor
Definition: packed_func.h:233
- Template Parameters
-
R | The return value of the function. |
Args | The argument signature of the function. |
◆ TSelf
template<typename R , typename... Args>
short hand for this function type
◆ TypedPackedFunc() [1/8]
template<typename R , typename... Args>
◆ TypedPackedFunc() [2/8]
template<typename R , typename... Args>
◆ TypedPackedFunc() [3/8]
template<typename R , typename... Args>
construct by wrap a PackedFunc
Example usage:
int x = args[0];
*rv = x + 1;
});
ICHECK_EQ(ftyped(1), 2);
friend class TVMRetValue
Definition: packed_func.h:366
Definition: packed_func.h:38
- Parameters
-
packed | The packed function |
◆ TypedPackedFunc() [4/8]
template<typename R , typename... Args>
◆ TypedPackedFunc() [5/8]
template<typename R , typename... Args>
◆ TypedPackedFunc() [6/8]
template<typename R , typename... Args>
◆ TypedPackedFunc() [7/8]
template<typename R , typename... Args>
template<typename FLambda , typename = typename std::enable_if<std::is_convertible< FLambda, std::function<R(Args...)>>::value>::type>
construct from a lambda function with the same signature.
Example usage:
auto typed_lambda = [](int x)->int { return x + 1; }
ICHECK_EQ(ftyped(1), 2);
- Parameters
-
typed_lambda | typed lambda function. |
name | the name of the lambda function. |
- Template Parameters
-
FLambda | the type of the lambda function. |
◆ TypedPackedFunc() [8/8]
template<typename R , typename... Args>
template<typename FLambda , typename = typename std::enable_if<std::is_convertible< FLambda, std::function<R(Args...)>>::value>::type>
construct from a lambda function with the same signature.
This version does not take a name. It is highly recommend you use the version that takes a name for the lambda.
Example usage:
auto typed_lambda = [](int x)->int { return x + 1; }
ICHECK_EQ(ftyped(1), 2);
- Parameters
-
typed_lambda | typed lambda function. |
- Template Parameters
-
FLambda | the type of the lambda function. |
◆ AssignTypedLambda() [1/2]
template<typename R , typename... Args>
template<typename FType >
◆ AssignTypedLambda() [2/2]
template<typename R , typename... Args>
template<typename FType >
◆ operator PackedFunc()
template<typename R , typename... Args>
◆ operator!=()
template<typename R , typename... Args>
- Returns
- Whether the packed function is not nullptr
◆ operator()()
template<typename R , typename... Args>
Invoke the operator.
- Parameters
-
- Returns
- The return value.
◆ operator=() [1/2]
template<typename R , typename... Args>
template<typename FLambda , typename = typename std::enable_if< std::is_convertible<FLambda, std::function<R(Args...)>>::value>::type>
copy assignment operator from typed lambda
Example usage:
ftyped = [](int x) { return x + 1; }
ICHECK_EQ(ftyped(1), 2);
- Parameters
-
typed_lambda | typed lambda function. |
- Template Parameters
-
FLambda | the type of the lambda function. |
- Returns
- reference to self.
◆ operator=() [2/2]
template<typename R , typename... Args>
copy assignment operator from PackedFunc.
- Parameters
-
packed | The packed function. |
- Returns
- reference to self.
◆ operator==()
template<typename R , typename... Args>
- Returns
- Whether the packed function is nullptr
◆ packed()
template<typename R , typename... Args>
◆ TVMRetValue
template<typename R , typename... Args>
The documentation for this class was generated from the following file: