3 ms·
If you read carefully, I said use move semantics to implement containers. That includes std::unique_ptr (a container for pointers with a deleter). The point is
by jfkebwjsbx 6y ago
If you read carefully, I said use move semantics to implement containers. That includes std::unique_ptr (a container for pointers with a deleter).
The point is that you shouldn't be using rvalue ref parameters, std::forward, etc. in most of your code. Even std::move should be fairly rare.
- neutronicus 6y agoAny time you want to pass a named unique_ptr across an API boundary, you'll need to std::move it
- jfkebwjsbx 6y ago...which you should avoid as much as possible do. Passing std types across API boundaries is a code smell.
- MauranKilom 6y agoWhat? That's one of the primary motivations! "I have created an object and will pass its unique ownership to you." -> std::unique_ptr "This routine needs a function that takes two ints and returns a float (without putting all my code into headers)." -> std::function<float(int, int)>. Can you elaborate in what circumstance you should not pass std::types across API boundaries?
- jfkebwjsbx 6y agoThe heap allocation is an implementation detail. std::function is useful in some situations, but "without putting all my code into headers" is not a good argument.