While sending stl container by reference it's not as safe as may be. Does it make sense to wrap stl container by smart pointer to send as function argument?
template <typename T> void f(const std::unique_ptr<T> up) { ... } std::unique_ptr<std::vector<char>> array; f(std::move(array)); UPD: OK, let's narrow the question. I'm making an instance of some class. I should construct it with a container:
class MyClass { public: MyClass(const std::vector<int>& ar) : m_ar(ar) {}; private: std::vector<int> m_ar; }; std::vector<int> tmp_ar; tmp_ar.push_back(0); tmp_ar.push_back(1); tmp_ar.push_back(2); MyClass mc(tmp_ar); I do not want to copy a container while sending it to the constructor, then I use reference to a local variable. Something in this code makes me nervous.