cameron314 / concurrentqueue

A fast multi-producer, multi-consumer lock-free concurrent queue for C++11
Other
9.87k stars 1.69k forks source link

Compile error with enqueue_bulk #320

Closed pengweichu closed 1 year ago

pengweichu commented 1 year ago

I can't get it compiled with the below code:

std::vector<std::unique_ptr<MyClass>> data;
BlockingConcurrentqueue<std::unique_ptr<MyClass>, Traits> q;

auto size = data.size();

q.enqueue_bulk(data.begin(), size); // not ok
q.enqueue_bulk(std::move(data.begin()), size); // not ok

How can I get it compiled ?

Thanks

cameron314 commented 1 year ago

unique_ptr can only be moved, not copied. Try:

q.enqueue_bulk(std::make_move_iterator(data.begin()), size);
pengweichu commented 1 year ago

Solved, thanks.