Pass the unique_ptr vector for the function, const reference

I usually pass a vector containing raw pointers, such as:

someFunc(const std::vector<MyClass*>& classList){..}

I wonder if you can do the same with unique_ptr as follows:

 someFunc(const std::vector<std::unique_ptr<MyClass>>& classList){..}

? Does this mean the same thing ?, i.e. read-only.

+4
source share
1 answer

Yes, you can. No, this does not mean the same thing: it std::unique_ptrrepresents a resource belonging to a pointer. A common raw pointer can have many other semantics.

, operator[] std::unique_ptr s. const std::unique_ptr<T> , T, , .

+6

Source: https://habr.com/ru/post/1619596/


All Articles