-
Notifications
You must be signed in to change notification settings - Fork 740
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
not_null<shared_ptr> overhead #550
Comments
allows support of supporting std::unique_ptr based on @xaxxon's work fixes microsoft#89 fixes microsoft#550 fixes microsoft#651
allows support of supporting std::unique_ptr based on @xaxxon's work fixes microsoft#89 fixes microsoft#550 fixes microsoft#651
allows support of supporting std::unique_ptr based on @xaxxon's work fixes microsoft#89 fixes microsoft#550 fixes microsoft#651
allows support of supporting std::unique_ptr based on @xaxxon's work fixes microsoft#89 fixes microsoft#550 fixes microsoft#651
@neilmacintosh can this issue #550, #415 and #89 be closed now that |
Is the problem resolved or not? |
Using C++17 guaranteed elision helps with some of them, e.g. |
The issue is that in case of Line 107 in 1683d87
can we do here a std::is_pod check instead?
|
Thanks for pinging this old issue, sorry for the lag. I agree that’s reasonable, and FWIW, personally, if I were writing the code I’d write this general type alias (name can be bikeshedded; this is copied from cppfront where I use this for "in" parameters and it's called
which is generally useful, and change
to
Note this also solves the slight incongruence that right now the return value is sometimes Caveat: I haven't tried it on What do you think? |
What is your reason for |
@daschuer Good question! The direct answer is "generality": The decision to return by value or by The secondary answer is that I then saw doing it that way had (actual or potential) extra benefits:
(*) I wonder if |
Ah, thank you for explaination. |
I think Herb is following F.16: For “in” parameters, pass cheaply-copied types by value and others by reference to const. From the Reason section:
From the Enforcement section:
|
@daschuer sorry for the delay - I'll make a PR to implement Herb's suggestion and resolve this issue. |
Cool, thank you. |
Closes issue #550, which highlighted overhead in not_null::get for larger types such as shared_ptr. Every call to get would return a copy of the contained value. This PR implements Herb's suggestion for changing the return type of not_null::get. The not_null's value will now only be copied if it is "trivially copyable"; otherwise, it will be returned by const reference. Note: this change also forces the returned copy to be const.
What is the intended usage of not_null with std::shared_ptr? There is a significant overhead to wrapping std::shared_ptr in not_null because every access results in a costly copy of the shared_ptr. As not_null cannot be used with unique_ptr, it seems that not_null is not really usable with smart pointers in general.
The text was updated successfully, but these errors were encountered: