Added emplace variants of enqueue and try_enqueue #275
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds variants of
enqueue
andtry_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 (nameenqueue_emplace
could not be used because of collision with the previous variadic template function when using multiple arguments)try_enqueue_emplace
- a variant oftry_enqueue
that takes constructor arguments (same as above)try_enqueue_token_emplace
- a variant oftry_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.