8
0
Fork
You've already forked libpEpCxx11
0

locked_queue: Correct emplace functions using perfect-forwarding #2

Closed
opened 2022年12月06日 21:09:26 +01:00 by roker · 10 comments
Copy link

...like std::vector<T>::emplace_back() and std::queue<T>::emplace_back(), but without returning the reference to the added container element, to avoid copying.

See https://en.cppreference.com/w/cpp/container/queue/emplace

Adding locked_queue<T>::emplace_front() might be added for symmetry, too, because this locked_queue is a double-ended queue.

...like `std::vector<T>::emplace_back()` and `std::queue<T>::emplace_back()`, but without returning the reference to the added container element, to avoid copying. See https://en.cppreference.com/w/cpp/container/queue/emplace Adding `locked_queue<T>::emplace_front()` might be added for symmetry, too, because this `locked_queue` is a double-ended queue.
Copy link

@roker There is a lot of 'move semantics' and possibly superflous copies in all of the C++ code in all components.
I just dragon to fight that are worse than that, like... constantly.

@roker There is a lot of 'move semantics' and possibly superflous copies in all of the C++ code in all components. I just dragon to fight that are worse than that, like... constantly.
Copy link

@roker But i will fix this of course, thanks for pointing it out.
I hope you are well.

@roker But i will fix this of course, thanks for pointing it out. I hope you are well.
Copy link

if you feel like contributing via change requests or pull requests, you are very welcome to do that:
https://dev.pep.foundation/Adapter/Change%20Management

:)

if you feel like contributing via change requests or pull requests, you are very welcome to do that: https://dev.pep.foundation/Adapter/Change%20Management :)
Copy link

@roker There is a lot of 'move semantics' and possibly superflous copies in all of the C++ code in all components.
I just dragon to fight that are worse than that, like... constantly.

Not in mine, I hope so. :-D

> @roker There is a lot of 'move semantics' and possibly superflous copies in all of the C++ code in all components. > I just dragon to fight that are worse than that, like... constantly. Not in mine, I hope so. :-D
Copy link

@roker But i will fix this of course, thanks for pointing it out.
I hope you are well.

I just use this awesome locked_queue in one of my hobby projects where the element type is not copyable, so I had to add a moving emplace_back() which is missing in the "upstream" codebase. :-D

> @roker But i will fix this of course, thanks for pointing it out. > I hope you are well. I just use this awesome `locked_queue` in one of my hobby projects where the element type is not copyable, so I had to add a moving emplace_back() which is missing in the "upstream" codebase. :-D
Copy link

@roker
its as simple as

void emplace_back(const T&& data)

right?

@roker its as simple as ``` void emplace_back(const T&& data) ``` right?
Copy link

@roker solved, will be in next RC :)

@roker solved, will be in next RC :)
Copy link

@roker
its as simple as

void emplace_back(const T&& data)

right?

Nope.

The key feature of these "emplace" methods is the construction of the elements "in-place" inside the container by forwarding the c'tors parameters, like this:

template< class... Args >
void emplace_back( Args&&... args )
{
 {
 Lock L(_mtx);
 _q.emplace_back( std::forward<Args>(args)... );
 }
 _cv.notify_one();
}
> @roker > its as simple as > ``` > void emplace_back(const T&& data) > ``` > right? Nope. The key feature of these "emplace" methods is the construction of the elements "in-place" inside the container by forwarding the c'tors parameters, like this: ``` template< class... Args > void emplace_back( Args&&... args ) { { Lock L(_mtx); _q.emplace_back( std::forward<Args>(args)... ); } _cv.notify_one(); } ```
Copy link

@roker ahh yeah vague memories are surfacing...
hihi, bit ashamed and have to admit didnt do any real C++ in months now, and so quickly it all fades... shame.
Ok, will take care of that :)
thanks @roker

@roker ahh yeah vague memories are surfacing... hihi, bit ashamed and have to admit didnt do any real C++ in months now, and so quickly it all fades... shame. Ok, will take care of that :) thanks @roker
Copy link

@roker i almost cant write any code without the accoriding tests, trial-and-error kiddie i am.
So, will do exactly that :)

@roker i almost cant write any code without the accoriding tests, trial-and-error kiddie i am. So, will do exactly that :)
Sign in to join this conversation.
No Branch/Tag specified
master
Release_3.2
gitea-02
v3.3.1
v3.3.0
v3.3.0-RC0
v3.2.1
v3.2.0
v3.2.0-RC1
v3.2.0-RC0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pEp/libpEpCxx11#2
Reference in a new issue
pEp/libpEpCxx11
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?