Skip to content

Commit 763577b

Browse files
committed
WorkerThreadsPool: Modernize std::result_of usage to C++17
1 parent 47348f0 commit 763577b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

libs/core/include/mrpt/core/WorkerThreadsPool.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ class WorkerThreadsPool
8282
* available. */
8383
template <class F, class... Args>
8484
[[nodiscard]] auto enqueue(F&& f, Args&&... args)
85-
-> std::future<typename std::result_of<F(Args...)>::type>;
85+
-> std::future<std::invoke_result_t<F, Args...>>;
8686

8787
/** Returns the number of enqueued tasks, currently waiting for a free
8888
* working thread to process them. */
89-
std::size_t pendingTasks() const noexcept;
89+
[[nodiscard]] std::size_t pendingTasks() const noexcept;
9090

9191
/** Sets the private thread names of threads in this pool.
9292
* Names can be seen from debuggers, profilers, etc. and will follow
@@ -96,7 +96,7 @@ class WorkerThreadsPool
9696
void name(const std::string& name);
9797

9898
/** Returns the base name of threads in this pool */
99-
std::string name() const { return name_; }
99+
[[nodiscard]] std::string name() const { return name_; }
100100

101101
private:
102102
std::vector<std::thread> threads_;
@@ -110,16 +110,16 @@ class WorkerThreadsPool
110110

111111
template <class F, class... Args>
112112
auto WorkerThreadsPool::enqueue(F&& f, Args&&... args)
113-
-> std::future<typename std::result_of<F(Args...)>::type>
113+
-> std::future<std::invoke_result_t<F, Args...>>
114114
{
115-
using return_type = typename std::result_of<F(Args...)>::type;
115+
using return_type = std::invoke_result_t<F, Args...>;
116116

117117
auto task = std::make_shared<std::packaged_task<return_type()>>(
118118
std::bind(std::forward<F>(f), std::forward<Args>(args)...));
119119

120120
std::future<return_type> res = task->get_future();
121121
{
122-
std::unique_lock<std::mutex> lock(queue_mutex_);
122+
const std::unique_lock<std::mutex> lock(queue_mutex_);
123123

124124
// don't allow enqueueing after stopping the pool
125125
if (do_stop_) throw std::runtime_error("enqueue on stopped ThreadPool");

0 commit comments

Comments
 (0)