Are there any advantages of using std::unique_ptr<T>&
instead of std::unique_ptr<T>
? For example, in function arguments?
There are a few different situations
std::unique_ptr<T>
std::unique_ptr<T> &
T &
, and dereference at the call site T *
and call unique_ptr::get
at the call siteconst T &
, and dereference at the call siteconst T *
and call unique_ptr::get
at the call siteT
, and dereference at the call site<algorithm>
call) over a collection of unique_ptr<T>
, and want to observe the values, and don't have ranges::indirect
(or similar)
auto &
, and know that it is inferred as std::unique_ptr<T> &
(or const std::unique_ptr<T> &
if the collection is const
), so you have to dereference in the loop bodyIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With