I am creating a "job" that store unique pointers to basic "tasks"
class JobBase
{
protected:
template<typename... BaseOperations>
JobBase(const std::wstring& operationDescription, BaseOperations&&... args)
: m_operationDescription(operationDescription)
, m_BaseOperations{std::move<BaseOperations>(args)...}
{
}
private:
std::vector<std::unique_ptr<Task>> m_BaseOperations;
}
And create job with few tasks:
std::unique_ptr<Task> pTask = std::make_unique<Task>();
auto asyncCompOp2 = std::make_shared<Job>(L"AsyncOp", std::move(pTask));
But when I build my program I receive error:
Error C2664 'std::unique_ptr<Task,std::default_delete<_Ty>> &&std::move<std::unique_ptr<_Ty,std::default_delete<_Ty>>>(std::unique_ptr<_Ty,std::default_delete<_Ty>> &&) noexcept': cannot convert argument 1 from '_Ty' to '_Ty &&'
And I don't understant what is wrong. I created classic constructor, that accepts unique_ptr and emplaced passed value to vector and all working good. Task class now doesn't have members, dtor, copy/move operators and ctors. Please, help me undestand what I need to do
Full code sample
#include <memory>
#include <vector>
#include <string>
class Task
{
public:
void Run() {}
};
class Job
{
public:
template<typename... BaseOperations>
Job(const std::wstring& name, BaseOperations&&... args)
: m_Name(name)
, m_BaseOperations{ std::forward<BaseOperations>(args)... }
{
}
private:
std::wstring m_Name;
std::vector<std::unique_ptr<Task>> m_BaseOperations;
};
int main()
{
std::unique_ptr<Task> pOp3 = std::make_unique<Task>();
auto asyncCompOp2 = std::make_shared<Job>(L"AsyncOp", std::move(pOp3));
}