concurrentqueue icon indicating copy to clipboard operation
concurrentqueue copied to clipboard

Added emplace variants of enqueue and try_enqueue

Open gameraccoon opened this issue 4 years ago • 0 comments

This PR adds variants of enqueue and try_enqueue that construct queue elements in-place. This allows avoiding an extra move for potentially expensive to move objects.

The next functions were added:

  • enqueue_emplace - a variant of enqueue that takes constructor arguments of an element to construct the element in-place in the queue.
  • enqueue_token_emplace - a variant of enqueue that takes producer_token_t and constructor arguments to construct the element in-place in the queue (name enqueue_emplace could not be used because of collision with the previous variadic template function when using multiple arguments)
  • try_enqueue_emplace - a variant of try_enqueue that takes constructor arguments (same as above)
  • try_enqueue_token_emplace - a variant of try_enqueue that takes producer_token_t and constructor arguments (same as above)

Added simple unit tests to cover new functions.

The PR split into two commits: the change+tests, and refactoring to variable names.

I'm not sure whether it's a good contribution or not because it makes the code of the implementation a bit more complex, but it feels like a nice option to have for the users. Also not sure whether the chosen names fit nicely with the codebase. Feel free to make any changes.

gameraccoon avatar Dec 26 '21 22:12 gameraccoon