Turning vector of shared_ptr into vector of shared_ptr to const
问题 Let class A { std::vector<std::shared_ptr<int>> v_; }; Now I'd like to add access to v_ using two public member functions std::vector<std::shared_ptr<int>> const & v() { return v_; } and std::vector<std::shared_ptr<int const> const & v() const { TODO } I cannot replace TODO with return v_; though. One option would be to not return a reference but a copy. Apart from the obvious performance penalty, this would also make the interface somewhat less desirable. Another option is to make TODO equal