DarkSharpness commented on code in PR #266:
URL: https://github.com/apache/tvm-ffi/pull/266#discussion_r2532158017


##########
include/tvm/ffi/function.h:
##########
@@ -487,10 +497,10 @@ class Function : public ObjectRef {
    * \param callable the internal container of packed function.
    */
   template <typename TCallable>
-  static Function FromTyped(TCallable callable) {
-    using FuncInfo = details::FunctionInfo<TCallable>;
-    auto call_packed = [callable = std::move(callable)](const AnyView* args, 
int32_t num_args,
-                                                        Any* rv) mutable -> 
void {
+  static Function FromTyped(TCallable&& callable) {
+    using FuncInfo = details::FunctionInfo<std::decay_t<TCallable>>;
+    auto call_packed = [callable = std::forward<TCallable>(callable)](

Review Comment:
   In lambda expression, a capture without `&` will always store by value 
(init-capture in 
[cppreference](https://en.cppreference.com/w/cpp/language/lambda.html)). So 
callable capture is by value (just as `std::decay_t<TCallable>` instead of by 
reference. The `forward` here just means we will choose to copy or move 
construct the inner-captured value.
   
   `FuncInfo` is inherited from the old code. It is used to get the return type 
and num of arguments:
   
   ```cpp
     template <typename TCallable>
     static Function FromTyped(TCallable&& callable) {
       using FuncInfo = details::FunctionInfo<std::decay_t<TCallable>>;
       auto call_packed = [callable = std::forward<TCallable>(callable)](
                              const AnyView* args, int32_t num_args, Any* rv) 
mutable -> void {
         details::unpack_call<typename FuncInfo::RetType>(
             std::make_index_sequence<FuncInfo::num_args>{}, nullptr, callable, 
args, num_args, rv);
       };
       return FromPackedInternal(std::move(call_packed));
     }
     ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to