20 #include "tbb/task_group.h" 25 #include <type_traits> 32 template <
class Function,
class... Args>
34 threads_.push_back(std::async(std::launch::async, f,
args...));
41 template <
typename T,
typename ENABLE =
void>
50 for (
auto& child : this->threads_) {
63 std::vector<T> results;
64 results.reserve(this->
threads_.size());
68 for (
auto& child : this->threads_) {
69 results.push_back(child.get());
77 class TbbThreadPoolBase {
79 tbb::task_group tasks_;
82 template <
typename T,
typename ENABLE =
void>
83 class TbbThreadPool :
public TbbThreadPoolBase {
87 template <
class Function,
class... Args>
89 tasks_.run([f,
args...] { f(args...); });
92 void join() { tasks_.wait(); }
96 class TbbThreadPool<T, std::enable_if_t<std::is_object<T>::value>>
97 :
public TbbThreadPoolBase {
101 template <
class Function,
class... Args>
103 const size_t result_idx = results_.size();
104 results_.emplace_back(T{});
105 tasks_.run([
this, result_idx, f,
args...] { results_[result_idx] = f(args...); });
114 std::vector<T> results_;
120 template <
typename T>
123 template <
typename T>
void spawn(Function &&f, Args &&... args)
std::vector< std::future< T > > threads_