/*
- * 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) {
#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
std::rethrow_exception(e);
}
}
-
-}} // folly::fibers
+}
+} // folly::fibers