junrushao commented on code in PR #286:
URL: https://github.com/apache/tvm-ffi/pull/286#discussion_r2573266582


##########
include/tvm/ffi/reflection/registry.h:
##########
@@ -270,52 +274,49 @@ class ReflectionDefBase {
     }
   }
 
+  template <typename Func>
+  TVM_FFI_INLINE static Function GetMethod(std::string name, Func&& func) {
+    return ffi::Function::FromTyped(WrapFunction(std::forward<Func>(func)), 
std::move(name));
+  }
+
+  template <typename Func>
+  TVM_FFI_INLINE static Func&& WrapFunction(Func&& func) {
+    return std::forward<Func>(func);
+  }
   template <typename Class, typename R, typename... Args>
-  TVM_FFI_INLINE static Function GetMethod(std::string name, R 
(Class::*func)(Args...)) {
+  TVM_FFI_INLINE static auto WrapFunction(R (Class::*func)(Args...)) {

Review Comment:
   Curious what the return type is for small-brain human beings like me :)



##########
tests/cpp/test_overload.cc:
##########
@@ -0,0 +1,95 @@
+

Review Comment:
   nit: remove blank line



##########
include/tvm/ffi/function.h:
##########
@@ -166,21 +171,19 @@ class FunctionObjImpl : public FunctionObj {
 
   /*!
    * \brief Derived object class for constructing ffi::FunctionObj.
-   * \param callable The type-erased callable object (rvalue).
-   */
-  explicit FunctionObjImpl(TCallable&& callable) : 
callable_(std::move(callable)) {
-    this->safe_call = SafeCall;
-    this->cpp_call = reinterpret_cast<void*>(CppCall);
-  }
-  /*!
-   * \brief Derived object class for constructing ffi::FunctionObj.
-   * \param callable The type-erased callable object (lvalue).
+   * \param args The arguments to construct TCallable
    */
-  explicit FunctionObjImpl(const TCallable& callable) : callable_(callable) {
+  template <typename... Args>
+  explicit FunctionObjImpl(Args&&... args) : 
callable_(std::forward<Args>(args)...) {
     this->safe_call = SafeCall;
     this->cpp_call = reinterpret_cast<void*>(CppCall);
   }
 
+  FunctionObjImpl(const FunctionObjImpl&) = delete;
+  FunctionObjImpl& operator=(const FunctionObjImpl&) = delete;
+
+  TCallable& GetCallable() { return callable_; }

Review Comment:
   nit: For some reason our convention is to always return pointers instead of 
references, so it would be better if we do
   
   ```suggestion
     TCallable* GetCallable() { return &callable_; }
   ```



-- 
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