16 ms·
If you _maybe_ need to share ownership, the second is a little pessimistic - you always increase the ref count.
by a_t48 2y ago
If you _maybe_ need to share ownership, the second is a little pessimistic - you always increase the ref count.
- Maxatar 2y agoThat is correct and I can see that being a justification for passing a const&, in fact the C++ Core Guidelines agree with you that such a scenario is the only acceptable reason for passing a shared_ptr by const&, although they encourage passing by value, or just passing a const T&.
- a_t48 2y agoObviously the correct way is to accept a templated type and use perfect forwarding. /s /s /s /s /s
- worstspotgain 2y agoBonus points for using static_cast<T &&>(p) instead of std::forward<T>(p) ;)