Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added emplace variants of enqueue and try_enqueue #275

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gameraccoon
Copy link

@gameraccoon gameraccoon commented Dec 26, 2021

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.

…he type from 'U' to 'Args' for internal methods to denote that these are constructor arguments
netborg-afps added a commit to netborg-afps/dxvk that referenced this pull request Jul 27, 2023
netborg-afps added a commit to netborg-afps/dxvk that referenced this pull request Sep 21, 2023
netborg-afps added a commit to netborg-afps/dxvk that referenced this pull request Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant