diff --git a/include/tev/Common.h b/include/tev/Common.h index 454f50c3..f86799b3 100644 --- a/include/tev/Common.h +++ b/include/tev/Common.h @@ -406,7 +406,7 @@ template void forEachFileInDir(bool recursive, const fs::path& path template class ScopeGuard { public: ScopeGuard(const F& callback) : mCallback{callback} {} - ScopeGuard(F&& callback) : mCallback{std::move(callback)} {} + ScopeGuard(F&& callback) : mCallback{std::forward(callback)} {} ScopeGuard(const ScopeGuard& other) = delete; ScopeGuard& operator=(const ScopeGuard& other) = delete; ScopeGuard(ScopeGuard&& other) { *this = std::move(other); } diff --git a/include/tev/Task.h b/include/tev/Task.h index dc211a22..33a8c7b2 100644 --- a/include/tev/Task.h +++ b/include/tev/Task.h @@ -237,12 +237,12 @@ template concept TaskCoroutine = std::invocable && is_task Task invokeTask(F&& executor, Args&&... args) { auto exec = std::forward(executor); - co_await exec(args...); + co_await exec(std::forward(args)...); } template DetachedTask invokeTaskDetached(F&& executor, Args&&... args) { auto exec = std::forward(executor); - co_await exec(args...); + co_await exec(std::forward(args)...); } void waitAll(range_of> auto&& futures) { diff --git a/include/tev/ThreadPool.h b/include/tev/ThreadPool.h index d980cff1..083e57f4 100644 --- a/include/tev/ThreadPool.h +++ b/include/tev/ThreadPool.h @@ -155,7 +155,7 @@ class ThreadPool { } template F> - Task parallelFor(Int start, Int end, size_t approxCost, F body, int priority) { + Task parallelFor(Int start, Int end, size_t approxCost, F&& body, int priority) { const Int range = end - start; const Int n = nTasks(start, end, approxCost); @@ -190,7 +190,7 @@ class ThreadPool { } template F> - Task parallelFor(Int start, Int end, size_t approxCost, F body, int priority) { + Task parallelFor(Int start, Int end, size_t approxCost, F&& body, int priority) { co_await parallelFor( start, end, @@ -211,12 +211,13 @@ class ThreadPool { } template F> - void parallelForSync(Int start, Int end, size_t approxCost, F body, int priority) { - blockAndDrain(parallelFor(start, end, approxCost, body, priority)); + void parallelForSync(Int start, Int end, size_t approxCost, F&& body, int priority) { + blockAndDrain(parallelFor(start, end, approxCost, std::forward(body), priority)); } - template F> void parallelForSync(Int start, Int end, size_t approxCost, F body, int priority) { - blockAndDrain(parallelFor(start, end, approxCost, body, priority)); + template F> + void parallelForSync(Int start, Int end, size_t approxCost, F&& body, int priority) { + blockAndDrain(parallelFor(start, end, approxCost, std::forward(body), priority)); } size_t numThreads() const { return mNumThreads; }