Open littlebirds opened 6 years ago
Wow, this really works! I would have though that a packaged_task<int()>
couldn't be moved into a packaged_task<void()>
. Are there any disadvantages?
the advantage will be that:
- in enqueue() method you no longer need to make a shared_ptr of packaged_task,
- tasks.emplace(task{ (*task)(); }); === ==> tasks.emplace(std::move(task))
The change works fine on g++ 6.2.0, so I wonder if current implementation is due to compatibility back then?
msvc will not compile... although it is a msvc bug.
@littlebirds Unfortunately this implies task
and tasks
should be the same type. This means users will be able to enqueue callables with the same signature only. In the original implementation one can do:
pool.enqueue([](int a){return a*42;});
pool.enqueue([](string s){return "Hello"+s;});
In the proposed implementation it will be impossible since all the callables should be the same signature (return and parameters type).
the advantage will be that: 1) in enqueue() method you no longer need to make a shared_ptr of packaged_task, 2) tasks.emplace([task](){ (*task)(); }); === ==> tasks.emplace(std::move(task))
The change works fine on g++ 6.2.0, so I wonder if current implementation is due to compatibility back then?