range based for loop with const shared_ptr<>
问题 I have a container with shared_ptr<> , e.g. a vector<shared_ptr<string>> v and I'd like to iterate over v indicating const-ness. This code: vector<shared_ptr<string>> v; v.push_back(make_shared<std::string>("hallo")); ... for (const auto &s : v) { *s += "."; // <<== should be invalid } looks like what I want to do (indicating that s is const ) but of course it does not make the string const . Is there an elegant way to iterate over a container of shared_ptr which makes clear that the content