Accept auto_ptr<T> where T is derived type

Without the member template it is not possible to pass an auto_ptr
instantiated with a derived type to post() or broadcast().

The reason is that the conversion constructor and conversion
operator of auto_ptr are equally good for that purpose, and hence
the compilation ends with an error.
This commit is contained in:
Johan Wikman 2017-05-04 15:00:53 +03:00
parent 5dc49a59be
commit f66620c89c
2 changed files with 18 additions and 5 deletions

View File

@ -298,6 +298,12 @@ public:
*/
bool post(std::auto_ptr<DisposableTask> sTask, enum execute_mode_t mode = EXECUTE_AUTO);
template<class T>
bool post(std::auto_ptr<T> sTask, enum execute_mode_t mode = EXECUTE_AUTO)
{
return post(std::auto_ptr<DisposableTask>(sTask.release()), mode);
}
/**
* Posts a task to all workers for execution.
*
@ -331,6 +337,12 @@ public:
*/
static size_t broadcast(std::auto_ptr<DisposableTask> sTask);
template<class T>
static size_t broadcast(std::auto_ptr<T> sTask)
{
return broadcast(std::auto_ptr<DisposableTask>(sTask.release()));
}
/**
* Executes a task on all workers in serial mode (the task is executed
* on at most one worker thread at a time). When the function returns

View File

@ -49,17 +49,18 @@ public:
*/
class WorkerDisposableTask
{
public:
/**
* Destructor
*/
virtual ~WorkerDisposableTask();
protected:
/**
* Constructor
*/
WorkerDisposableTask();
/**
* Destructor
*/
virtual ~WorkerDisposableTask();
/**
* @brief Called in the context of a specific worker.
*