dynamically-sized text object with a copy constructor, a trivial assignment operator, and a trivial destructor

前端 未结 2 2089
無奈伤痛
無奈伤痛 2021-01-24 01:03

I\'ve been shown that a std::string cannot be inserted into a boost::lockfree::queue.

boost::lockfree::queue is too valuable to ab

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 01:56

    A dynamically-size type with a trivial copy ctor/dtor is not possible. There are two solutions to your problem, use a fixed sized type, or store pointers in the queue:

    boost::lockfree::queue queue(some_size);
    // push on via new
    queue.push(new std::string("blah"));
    // pop and delete
    std::string* ptr;
    if(queue.pop(ptr))
    {
       delete ptr;
    }
    

提交回复
热议问题