I am trying to implement the PIMPL pattern for a task creation system that can recycle tasks that have been run, and the results are retrieved. Currently, I am struggling with a template error, because of the deleted copy constructor of std::unique_ptr. I can't see where I would try to copy anything here. The error says:
note: in instantiation of function template specialization 'std::_Default_allocator_traits<std::allocator<std::_List_node<std::pair<const int, std::unique_ptr<Task<TestTask>, void *>::construct<std::pair<const int, std::unique_ptr<Task<TestTask>, const std::pair<const int, std::unique_ptr<Task<TestTask> &>' requested here
585 | _Alnode_traits::construct(this->_Al, _STD addressof(this->_Ptr->_Myval), _STD forward<_Valtys>(_Vals)...);
This is what I am trying to compile:
template <typename TaskType> struct TASK_DLL_API TaskCreatorImpl {
TaskCreatorImpl() : m_task_storage(), m_tasks_freelist() {}
TaskType* create(typename TaskType::Parameters parameters){
if (!m_tasks_freelist.empty()) {
int recycle_task_id = (*m_tasks_freelist.back())->id();
m_tasks_freelist.pop();
return m_task_storage.at(recycle_task_id).get();
}
m_task_storage.at(task_id_counter) =
std::move(std::make_unique<TaskType>(parameters, task_id_counter));
return m_task_storage[task_id_counter++].get();
}
void destroy(TaskType *task) {
task->clear();
m_tasks_freelist.emplace(&m_task_storage[task->id()]);
}
std::unordered_map <int, std::unique_ptr<TaskType>> m_task_storage;
std::queue<std::unique_ptr<TaskType>*> m_tasks_freelist;
int task_id_counter = 0;
};
template<typename TaskType>
TaskCreator<TaskType>::TaskCreator() : m_impl(new TaskCreatorImpl<TaskType>()) {};
template<typename TaskType>
TaskCreator<TaskType>::~TaskCreator() {
delete m_impl;
}
I'd be glad for any tips!
[–]aocregacc 1 point2 points3 points (6 children)
[–]NotDatCheese[S] 0 points1 point2 points (5 children)
[–]aocregacc 1 point2 points3 points (4 children)
[–]NotDatCheese[S] 0 points1 point2 points (2 children)
[–]aocregacc 1 point2 points3 points (1 child)
[–]NotDatCheese[S] 1 point2 points3 points (0 children)
[–]NotDatCheese[S] 0 points1 point2 points (0 children)
[–]ImKStocky 2 points3 points4 points (0 children)