adding Promise::await
[folly.git] / folly / experimental / fibers / ForEach-inl.h
index ed5b72d6b8b47ed6ed97611136795ab0b1eee080..85333b394b970e9c2afc53aa321c2482fa8872ba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 #include <folly/experimental/fibers/FiberManager.h>
 
-namespace folly { namespace fibers {
+namespace folly {
+namespace fibers {
 
 namespace {
 
 template <class F, class G>
 typename std::enable_if<
-  !std::is_same<typename std::result_of<F()>::type, void>::value, void>::type
-inline callFuncs(F&& f, G&& g, size_t id) {
+    !std::is_same<typename std::result_of<F()>::type, void>::value,
+    void>::type inline callFuncs(F&& f, G&& g, size_t id) {
   g(id, f());
 }
 
 template <class F, class G>
 typename std::enable_if<
-  std::is_same<typename std::result_of<F()>::type, void>::value, void>::type
-inline callFuncs(F&& f, G&& g, size_t id) {
+    std::is_same<typename std::result_of<F()>::type, void>::value,
+    void>::type inline callFuncs(F&& f, G&& g, size_t id) {
   f();
   g(id);
 }
 
-}  // anonymous namespace
+} // anonymous namespace
 
 template <class InputIterator, class F>
 inline void forEach(InputIterator first, InputIterator last, F&& f) {
@@ -52,20 +53,25 @@ inline void forEach(InputIterator first, InputIterator last, F&& f) {
 #pragma clang diagnostic push // ignore generalized lambda capture warning
 #pragma clang diagnostic ignored "-Wc++1y-extensions"
 #endif
-  auto taskFunc =
-    [&tasksTodo, &e, &f, &baton] (size_t id, FuncType&& func) {
-    return [id, &tasksTodo, &e, &f, &baton,
-            func_ = std::forward<FuncType>(func)]() mutable {
-        try {
-          callFuncs(std::forward<FuncType>(func_), f, id);
-        } catch (...) {
-          e = std::current_exception();
-        }
-        if (--tasksTodo == 0) {
-          baton.post();
-        }
-      };
+  auto taskFunc = [&tasksTodo, &e, &f, &baton](size_t id, FuncType&& func) {
+    return [
+      id,
+      &tasksTodo,
+      &e,
+      &f,
+      &baton,
+      func_ = std::forward<FuncType>(func)
+    ]() mutable {
+      try {
+        callFuncs(std::forward<FuncType>(func_), f, id);
+      } catch (...) {
+        e = std::current_exception();
+      }
+      if (--tasksTodo == 0) {
+        baton.post();
+      }
     };
+  };
 #ifdef __clang__
 #pragma clang diagnostic pop
 #endif
@@ -84,5 +90,5 @@ inline void forEach(InputIterator first, InputIterator last, F&& f) {
     std::rethrow_exception(e);
   }
 }
-
-} // folly::fibers
+}
+} // folly::fibers