In-place construction for Try
[folly.git] / folly / Try.h
index f115a34ab333db0961556f3571415cfd36773366..df48794e656258c3dbc4639e65027407b4b1ea42 100644 (file)
@@ -21,6 +21,7 @@
 #include <folly/Memory.h>
 #include <folly/Portability.h>
 #include <folly/Unit.h>
+#include <folly/Utility.h>
 #include <exception>
 #include <stdexcept>
 #include <type_traits>
@@ -81,6 +82,11 @@ class Try {
    */
   explicit Try(T&& v) : contains_(Contains::VALUE), value_(std::move(v)) {}
 
+  template <typename... Args>
+  explicit Try(in_place_t, Args&&... args) noexcept(
+      noexcept(::new (nullptr) T(std::declval<Args&&>()...)))
+      : contains_(Contains::VALUE), value_(std::forward<Args>(args)...) {}
+
   /// Implicit conversion from Try<void> to Try<Unit>
   template <class T2 = T>
   /* implicit */