I'm trying to create a Queue using boost::lockfree:queue from an own declared type. I checked the Class template for queue for the requirements:
- T must have a copy constructor
- T must have a trivial assignment operator
- T must have a trivial destructor
So I implemeted the following class:
namespace ek {
class SourceQueueElement{
private:
int id;
std::string fileName;
public:
SourceQueueElement(int id, std::string fileName);
SourceQueueElement(const SourceQueueElement &rhs);
SourceQueueElement& operator=(const SourceQueueElement& rhs);
~SourceQueueElement();
int getId();
void setId(int id);
std::string getFileName();
void setFileName(std::string fileName);
};}
And implemented the methods:
#include "sourcequeueelement.h"
ek::SourceQueueElement::SourceQueueElement(int id, std::string fileName){
this->id = id;
this->fileName = fileName;
}
ek::SourceQueueElement::SourceQueueElement(const ek::SourceQueueElement &rhs){
this->setFileName(rhs.getFileName());
this->setId(rhs.getId());
}
ek::SourceQueueElement::~SourceQueueElement(){
this->id = 0;
this->fileName = null;
}
ek::SourceQueueElement& operator=(const ek::SourceQueueElement &rhs){
this->setFileName(rhs.getFileName());
this->setId(rhs.getId());
return *this;
}
The method implementation is really simple I think. The problem is, that trying to use the class in the boost::lockfree_queue fails:
boost::lockfree::queue<ek::SourceQueueElement> sourceQueue(256);
with the following error:
/usr/include/boost/lockfree/queue.hpp:87:5: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
BOOST_STATIC_ASSERT((boost::has_trivial_destructor<T>::value));
/usr/include/boost/lockfree/queue.hpp:91:5: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
BOOST_STATIC_ASSERT((boost::has_trivial_assign<T>::value));
I know that according to this Stack Overflow question this error occurs if the requirements for the queue are not complied. E.g. if you try to use std::string as T for boost::lockfree:queue. But I think I have implemented the needed methods in my class. Does anybody know which is the problem or have I misinterpreted the requirements?
Thanks for your help.