Function::asStdFunction()
[folly.git] / folly / Function.h
index 1f6238edf825c14aad14c0f5420d62631640822f..399efd54c17c2298f8296d30ba4ce432ad645c6c 100644 (file)
@@ -303,6 +303,16 @@ class Function final
    */
   Function& operator=(Function&& rhs) noexcept(hasNoExceptMoveCtor());
 
+  /**
+   * Construct a std::function by moving in the contents of this `Function`.
+   * Note that the returned std::function will share its state (i.e. captured
+   * data) across all copies you make of it, so be very careful when copying.
+   */
+  std::function<typename Traits::NonConstFunctionType> asStdFunction() && {
+    return detail::function::InvokeFromSharedPtr<Function>(
+        std::make_shared<Function>(std::move(*this)));
+  }
+
   /**
    * Constructs a `Function` by moving from one with different template
    * parameters with regards to const-ness, no-except-movability and internal