mercredi 6 mai 2020

c++ How to pass an rvalue Reference to another function

I'm using the embedded templated library with etl::queue

https://www.etlcpp.com/queue.html

the etl::queue is quitvalent to std::queue

In order to avoid copying I'd like to actually move the element into the queue.

Now my setup looks like this

  bool CETLConcurrentQueue<ElementType_T, u32QueueSize>::Add(ElementType_T &&element, const uint32_t u32Timeout)
{
   //lock mutex...
   queue.push(element);
   //do further stuff
}

Now I'm not using queue.push(std::move(element)); because element is allready an rvalue Reference

However, queue.push(element); calls elements copy constructor (which is deleted) How can I call elements move constructor instead?

Aucun commentaire:

Enregistrer un commentaire