Better template deduction when posting tasks to the ThreadPool
This commit is contained in:
parent
6af462472a
commit
c54bba71db
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue