Better template deduction when posting tasks to the ThreadPool

This commit is contained in:
nsubiron 2019-04-18 12:26:49 +02:00
parent 6af462472a
commit c54bba71db
2 changed files with 4 additions and 3 deletions

View File

@ -15,6 +15,7 @@
#include <future>
#include <thread>
#include <type_traits>
namespace carla {
@ -35,7 +36,7 @@ namespace carla {
}
/// Post a task to the pool.
template <typename ResultT, typename FunctorT>
template <typename FunctorT, typename ResultT = typename std::result_of<FunctorT()>::type>
std::future<ResultT> Post(FunctorT &&functor) {
auto task = std::packaged_task<ResultT()>(std::forward<FunctorT>(functor));
auto future = task.get_future();

View File

@ -306,7 +306,7 @@ TEST(road, iterate_waypoints) {
std::vector<std::future<void>> results;
for (const auto& file : util::OpenDrive::GetAvailableFiles()) {
carla::logging::log("Parsing", file);
results.push_back(pool.Post<void>([file]() {
results.push_back(pool.Post([file]() {
carla::StopWatch stop_watch;
auto m = OpenDriveParser::Load(util::OpenDrive::Load(file));
ASSERT_TRUE(m.has_value());
@ -383,7 +383,7 @@ TEST(road, get_waypoint) {
std::vector<std::future<void>> results;
for (const auto& file : util::OpenDrive::GetAvailableFiles()) {
carla::logging::log("Parsing", file);
results.push_back(pool.Post<void>([file]() {
results.push_back(pool.Post([file]() {
carla::StopWatch stop_watch;
auto m = OpenDriveParser::Load(util::OpenDrive::Load(file));
ASSERT_TRUE(m.has_value());