Lift the invoke helper in Function.h
[folly.git] / folly / Function.h
index a73a8b7a4484203bf4927634b3d01edc9427ddb6..8cff8d8bb6b519e045c837f67462e10766ba46a6 100644 (file)
 #include <folly/CppAttributes.h>
 #include <folly/Portability.h>
 #include <folly/Traits.h>
+#include <folly/functional/Invoke.h>
 
 namespace folly {
 
@@ -405,19 +406,6 @@ bool execBig(Op o, Data* src, Data* dst) {
   return true;
 }
 
-// Invoke helper
-template <typename F, typename... Args>
-inline constexpr auto invoke(F&& f, Args&&... args)
-    -> decltype(std::forward<F>(f)(std::forward<Args>(args)...)) {
-  return std::forward<F>(f)(std::forward<Args>(args)...);
-}
-
-template <typename M, typename C, typename... Args>
-inline constexpr auto invoke(M(C::*d), Args&&... args)
-    -> decltype(std::mem_fn(d)(std::forward<Args>(args)...)) {
-  return std::mem_fn(d)(std::forward<Args>(args)...);
-}
-
 } // namespace function
 } // namespace detail
 
@@ -802,7 +790,7 @@ class FunctionRef<ReturnType(Args...)> final {
   template <typename Fun>
   static ReturnType call(void* object, Args&&... args) {
     using Pointer = _t<std::add_pointer<Fun>>;
-    return static_cast<ReturnType>(detail::function::invoke(
+    return static_cast<ReturnType>(invoke(
         static_cast<Fun&&>(*static_cast<Pointer>(object)),
         static_cast<Args&&>(args)...));
   }