Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable multi_future::get for void multi futures #62

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions BS_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,29 @@ class [[nodiscard]] multi_future
multi_future(const size_t num_futures_ = 0) : f(num_futures_) {}

/**
* @brief Get the results from all the futures stored in this multi_future object.
* @brief Get the results from all the futures stored in this multi_future object, re-throwing any stored exceptions.
*
* @return A vector containing the results.
*/
[[nodiscard]] std::vector<T> get()
template<typename V = T>
[[nodiscard]] std::enable_if_t<!std::is_same_v<void, V>, std::vector<T>> get()
{
std::vector<T> results(f.size());
for (size_t i = 0; i < f.size(); ++i)
results[i] = f[i].get();
return results;
}

/**
* @brief Get the results from all the void futures stored in this multi_future object, re-throwing any stored exceptions.
*/
template<typename V = T>
std::enable_if_t<std::is_same_v<void, V>, void> get()
{
for (size_t i = 0; i < f.size(); ++i)
f[i].get();
}

/**
* @brief Wait for all the futures stored in this multi_future object.
*/
Expand Down