Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assertion failure in case of boost::lockfree:queue default constructor

How can I use boost::lockfree:queue objects?

I'm trying to write an application that constructs an object of this class via default constructor, but it gives me an assertion failure inside the boost sources:

BOOST_ASSERT(has_capacity);

How can I use the default constructor for this class? Do I need to specify the size of the queue via template arguments?

like image 462
FrozenHeart Avatar asked Feb 26 '14 08:02

FrozenHeart


1 Answers

The capacity can be given statically, so it's even before the default constructor.

boost::lockfree::queue<int, boost::lockfree::capacity<50> > my_queue;

The mechanism resembles named parameters for template arguments.

See it Live On Coliru

#include <boost/lockfree/queue.hpp>
#include <iostream>

using namespace boost::lockfree;

struct X { int i; std::string s; };

int main()
{
    queue<int, boost::lockfree::capacity<50> > q;
}
like image 101
sehe Avatar answered Sep 28 '22 01:09

sehe