From ffe2e141834d80e12a41251a5dfe4ad9581a1baa Mon Sep 17 00:00:00 2001 From: eladalon Date: Thu, 31 Aug 2017 04:36:05 -0700 Subject: [PATCH] Allow PostTask() to take unique_ptr to classes derived of QueuedTask Problem fixed by this CL: Let DerivedQueuedTask be a custom derivation of QueuedTask. Calling PostTask() with a std::unique_ptr does not work, because overload resolution sees PostTask(const Closure& closure) as a better match. The workaround of explicitly converting to std::unique_ptr before calling PostTask() results in less readable code. Solution: Use std::enable_if to limit the template, thereby making the compiler use the right version of PostTask(). BUG=webrtc:8188 Review-Url: https://codereview.webrtc.org/3006933002 Cr-Commit-Position: refs/heads/master@{#19625} --- webrtc/rtc_base/task_queue.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/webrtc/rtc_base/task_queue.h b/webrtc/rtc_base/task_queue.h index e7eac2f185..0d9630bbf4 100644 --- a/webrtc/rtc_base/task_queue.h +++ b/webrtc/rtc_base/task_queue.h @@ -14,6 +14,7 @@ #include #include #include +#include #if defined(WEBRTC_MAC) #include @@ -189,7 +190,12 @@ class LOCKABLE TaskQueue { // more likely). This can be mitigated by limiting the use of delayed tasks. void PostDelayedTask(std::unique_ptr task, uint32_t milliseconds); - template + // std::enable_if is used here to make sure that calls to PostTask() with + // std::unique_ptr would not end up being + // caught by this template. + template ::value>::type* = nullptr> void PostTask(const Closure& closure) { PostTask(std::unique_ptr(new ClosureTask(closure))); }