【发布时间】:2019-06-10 14:36:30
【问题描述】:
当尝试将“事件”插入到无锁加速队列中时,我收到: 错误:静态断言失败:(boost::has_trivial_destructor::value)和静态断言失败:(boost::has_trivial_assign::value)。我知道容器的要求是: T 必须有一个复制构造函数 T 必须有一个平凡的赋值运算符 T 必须有一个简单的析构函数 我不确定为什么我的事件类不符合这些要求。
我已阅读此问题/答案:/boost/lockfree/queue.hpp: error: static assertion failed: (boost::has_trivial_destructor<T>::value)。我不明白为什么我的班级不满足要求。
struct Event
{
typedef uint8_t Event_Type;
//event bitmask..
enum : uint8_t
{
SS = 1,
TS = 2
};
static constexpr uint8_t BOTH = SS | TS;
Event(): _time {}
,_data1 {}
,_eventType {}
,_data2 {}
{}
Event(const Event& event_)
{
_id = event_._id;
_time = event_._time;
_data1 = event_.data1;
_eventType = event_._eventType;
_data2 = event_.data2;
}
template<Event_Type type, typename... Args >
void update(Args...args)
{
_eventType |= type;
apply(std::forward<Args>(args)...);
}
void apply(int32_t d)
{
data1 = d;
}
void apply(bool b)
{
data2= b;
}
template<typename Event, typename... Args>
void apply(Event event, Args... args)
{
apply(event);
apply(args...);
}
std::string _id;
int64_t _time;
int32_t _data1;
Event_Type _eventType;
bool _data2;
};
boost::lockfree::queue<Event, boost::lockfree::fixed_sized<false>> q;
Event e;
e._id="test";
q.push(event);
/boost/1.57.0/include/boost/static_assert.hpp:78:41:错误:静态断言失败:(boost::has_trivial_destructor::value) # 定义 BOOST_STATIC_ASSERT( ... ) static_assert(VA_ARGS, #VA_ARGS)
boost/1.57.0/include/boost/static_assert.hpp:78:41:错误:静态断言失败:(boost::has_trivial_assign::value) # 定义 BOOST_STATIC_ASSERT( ... ) static_assert(VA_ARGS, #VA_ARGS)
【问题讨论】: